matplotlib.pyplot.contour 简单等高线绘制

contour(X, Y, Z)

X,Y是与Z形状相同的二维数组,可以通过 numpy.meshgrid()创建。

numpy.meshgrid()----从坐标向量返回坐标矩阵

生成的x,y坐标矩阵,组合形成网格点
a = np.array([1,2,3])          #a.shape  (3,)
b = np.array([11,22,33,44])    #b.shape  (4,)
x,y = np.meshgrid(a,b)

x                              #x.shape(4,3)

array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
       [1, 2, 3] ])

y                             #y.shape(4,3)

array([[11, 11, 11],
       [22, 22, 22],
       [33, 33, 33],
       [44, 44, 44]])        

 1)contour()

a = np.array([1,2,3])
z = np.array([[0,1,1],[1,0,1],[1,1,0]])
x,y = np.meshgrid(a,a)
plt.contour(x,y,z,3)          #数字3是等高线的数量

 

2)contourf() 返回填充等高线图,其他输入输出和contour()没有区别

a = np.array([1,2,3])
z = np.array([[0,1,1],[1,0,1],[1,1,0]])
x,y = np.meshgrid(a,a)
plt.contourf(x,y,z,3)         #contourf() 

 

posted @ 2019-03-31 22:12  西瓜草莓甘蔗  阅读(1628)  评论(0编辑  收藏  举报