python三维网格图_matplotlib:3D图中的网格

1586010002-jmsa.png

In matplotlib, how can I show a grid in 3D scatter plot?

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)

How do I do this?

解决方案

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()

ImSLW.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值