import numpy as np
import matplotlib.pyplot as plt
x = np.array([0, 1, 2])
y = np.array([0, 1])
X, Y = np.meshgrid(x, y)
print(X)
print(Y)
plt.plot(X, Y,
color='red', # 全部点设置为红色
marker='.', # 点的形状为圆点
linestyle='') # 线型为空,也即点与点之间不用线连接
plt.grid(True)
plt.show()
例2
import numpy as np
import matplotlib.pyplot as plt
def function(x1, x2):
return 0.1 * x1 ** 2 + 2 * x2 ** 2
# plt.figure(figsize=[9, 7])
x1, x2 = np.meshgrid(np.arange(-5.5, 1.0, 0.1), np.arange(-3.0, 1.0, 0.1))
print(x1)
print('n', x2)
plt.contour(x1, x2, function(x1, x2)) # 画出等高线
plt.xlabel('x1')
plt.ylabel('x2')
plt.show()



