小编use*_*130的帖子

为axes3d创建表面数据

好吧,我对这个问题表示歉意,但我要在这里拉扯我的头发。

我在 python 中加载了一个数据结构,格式如下:

[(1,0,#),(1,1,#),(1,2,#),(1,3,#),(2,0,#),(2,1,#) ... (26,3,#)]
Run Code Online (Sandbox Code Playgroud)

每次我希望在 z 轴上表示时, # 都是不同的数字。您可以看到 x 和 y 始终是整数。

绘制散点图很简单:

x,y,z = zip(*data)
fig = plt.figure()
ax = fig.gca(projection = '3d')
surface = ax.scatter(x, y, z)
plt.show()
Run Code Online (Sandbox Code Playgroud)

但说到表面,我可以看到两种方法:

1) Call ax.plot_trisurf(),它应该与一维数组一起工作,类似于ax.scatter()并且显然可以在这里工作,但对我来说给了我一个错误:

"AttributeError: Axes3D subplot object has not attribute 'plot_trisurf'"
Run Code Online (Sandbox Code Playgroud)

如果我使用以下位置的示例源代码,也会出现此错误: http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots,表明我的安装有问题 - 我的 Matplotlib 版本是 1.1.1rc ,. 例如,如果ax.plot_surface()调用 或 ,则不会出现此错误ax.scatter()

2)使用meshgrid()griddata()结合ax.plot_surface()- 无论哪种情况,在仔细阅读文档和示例两天之后,我仍然不明白如何在我的情况下正确使用它们,特别是在生成 Z 值时。

任何帮助将非常感激。

python matplotlib

5
推荐指数
1
解决办法
7043
查看次数

标签 统计

matplotlib ×1

python ×1