制作散射轮廓在python中,如果我有一组数据x, y, z我可以散布import matplotlib.pyplot as plt
plt.scatter(x,y,c=z)我如何得到plt.contourf(x,y,z)分散?
3 回答
慕容森
TA贡献1853条经验 获得超18个赞
使用tricontourf:
import matplotlib.tri as triimport matplotlib.pyplot as plt triang = tri.Triangulation(x, y)plt.tricontour(x, y, z, 15, linewidths=0.5, colors='k')plt.tricontourf(x, y, z, 15)
旧回复:
使用以下函数转换为contourf所需的格式:
from numpy import linspace, meshgridfrom matplotlib.mlab import griddatadef grid(x, y, z, resX=100, resY=100): "Convert 3 column data to matplotlib grid" xi = linspace(min(x), max(x), resX) yi = linspace(min(y), max(y), resY) Z = griddata(x, y, z, xi, yi) X, Y = meshgrid(xi, yi) return X, Y, Z
现在你可以这样做:
X, Y, Z = grid(x, y, z)plt.contourf(X, Y, Z)
添加回答
举报
0/150
提交
取消