【发布时间】:2017-04-14 11:03:01
【问题描述】:
我有一个点列表:
pointList = [ [x1,y1,z1], [x2,y2,z2], ... [xn,yn,zn]]
我想绘制这组点的等高线图。
我试试:
import matplotlib.pyplot as plt
pointList = [ [x1,y1,z1], [x2,y2,z2], ... [xn,yn,zn]]
x = [el[0] for el in pointList]
y = [el[1] for el in pointList]
z = [el[2] for el in pointList]
plt.contourf(x,y,z)
plt.show()
但我有这个例外:
TypeError: Input z must be a 2D array.
这很奇怪,因为在 matplotlib 的文档中我发现:
Call signatures:
contour(Z)
make a contour plot of an array Z. The level values are chosen automatically.
contour(X,Y,Z)
X, Y specify the (x, y) coordinates of the surface
所以我不明白为什么它会失败......
【问题讨论】:
-
你的点真的创造了一个表面吗?
X和Y是用于表面的唯一x和y值。它不适用于分散的数据 -
不明白。我应该如何“实际”创建一个曲面?
-
你有分散的数据(看起来),所以你需要使用副本中的方法将其转换为常规网格
标签: python matplotlib contour