matplotlib:3D 图中的网格 [英] matplotlib: grid in 3D plots
本文介绍了matplotlib:3D 图中的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 matplotlib
中,如何在 3D 散点图中显示网格?
In matplotlib
, how can I show a grid in 3D scatter plot?
在 2D 图中,我只做:plt.grid(True)
,它的作用就像一个魅力.现在使用 3D 绘图,相同的调用会返回警告:
In 2D plots I just do: plt.grid(True)
and it works like a charm. Now with 3D plots the same call returns a warning:
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)
我该怎么做?
推荐答案
您可以使用轴的网格方法来打开和关闭网格.
You can use the grid method of the axes to turn the grid on and off.
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()
这篇关于matplotlib:3D 图中的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文