python - matplotlib:3D 图中的网格

标签 python 3d matplotlib grid plot

matplotlib 中,如何在 3D 散点图中显示网格?

在 2D 绘图中,我只是这样做: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)

我该怎么做?

最佳答案

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

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

关于python - matplotlib:3D 图中的网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16279978/

相关文章:

python - 具有多个 y 轴的误差条图会产生 ValueError

python - 如何将 matplotlib 编辑选项卡添加到 Canvas 中显示的 seaborn 图中?

Python:是否有使用多个键的优化字典类型(类似于数据库)?

python - 将特定单词后的单词提取为列表

javascript - D3 强制布局 - 如何实现节点的 3D 外观?

python - 如何从 3D 不规则数据中切片 2D 网格?

python - Pandas - 每个点具有不同颜色图例的散点图

python - 在构建编码器/解码器模型之前训练自动编码器是否有效?

python - 将字典中的值映射到 Pandas 中列的子集的最快方法是什么?

algorithm - 计算体射线转换中的梯度