matplotlib:3D图中的网格

Ric*_*son 2 python 3d grid plot 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)
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

Mol*_*lly 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()
Run Code Online (Sandbox Code Playgroud)

有和没有网格的3d图

  • 我想你可以标记每个点或关键点.否则没有. (2认同)