Matplotlib 3d plot_wireframe

时间:2013-09-09 08:57:05

标签: python matplotlib

我在一个图中绘制了两个plot_wireframe。我是matplotlib的新手..我阅读了教程但仍有一些问题。

(1)如何更改线条的颜色并在图中添加图例?

 fig = plt.figure()
 ax = fig.add_subplot(111,projection='3d')
 ax.plot_wireframe(x,y,z1)
 ax.legend("View window")  # not correct.
 ax.plot_wireframe(x,y,z2)
 ax.legend("High window")
 plt.show()

(2)另一个问题是如果我使用鼠标旋转图形(在Win 7中),在我调整窗口大小之前它似乎没有更新。

enter image description here

1 个答案:

答案 0 :(得分:3)

要设置颜色或调整图例标签,请直接在绘图调用中设置:

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
ax.plot_wireframe(x,y,z1, color='r', label='View window')
ax.plot_wireframe(x,y,z2, color='c', label='High window')
ax.legend()   # call this to actually show the legend; but use label above to set the text.
plt.show()

如果您阅读documentation for plot,您会看到matplotlib中几乎所有绘图功能通常包含的几十个选项,以及各种线条和颜色。

我不知道用鼠标更新旋转;这可能与matplotlib使用的绘图后端有关。如果可能的话,你可以尝试另一个后端,看看它是否有效(backends上更多一点;不保证这会有效。)