2013-04-29 340 views
2

matplotlib中,如何在三维散点图中显示网格?matplotlib:三维图中的网格

在二维情节我只是:plt.grid(True)它的作品就像一个魅力。现在使用3D图,相同的调用返回警告:

File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2792, in grid 
    ret = gca().grid(b, which, axis, **kwargs)  
TypeError: grid() takes at most 2 arguments (4 given) 

我该如何做?

回答

5

可以使用轴的网格方法打开和关闭网格。

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 

fig = plt.figure() 
ax = fig.add_subplot(211, projection='3d') 
ax.plot([1,2,3,4,5],[7,4,6,2,8],[4,6,8,9,2],'*') 
ax.grid(True) 
ax.set_title('grid on') 

ax2 = fig.add_subplot(212, projection='3d') 
ax2.plot([1,2,3,4,5],[7,4,6,2,8],[4,6,8,9,2],'*') 
ax2.grid(False) 
ax2.set_title('grid off') 
plt.show() 

3d plot with and without grid

+0

那好吧,谢谢。然后我猜它默认打开了。事实证明,它不像在3D图中那样有用,以正确识别三个坐标。你知道有哪些方法可以使每个绘图点的三个坐标清晰吗? – 2013-04-29 15:47:42

+2

我想你可以标出每个点或关键点。否则不。 – Molly 2013-04-29 15:51:05

+0

@RickyRobinson你可以尝试生成立体对 – tacaswell 2013-04-29 18:26:31