如何在Axes3D绘图的Z轴显示次要刻度但不显示次要网格线?
Axes3D绘图:显示Z轴次要刻度但隐藏次要网格线
我需要在Matplotlib的Axes3D绘图中显示Z轴的次要刻度,但不显示对应的次要网格线。
初始绘图效果:
初始代码:
import numpy as np import matplotlib from matplotlib.figure import Figure test_fig = Figure() _x = np.arange(4) _y = np.arange(5) _xx, _yy = np.meshgrid(_x, _y) x, y = _xx.ravel(), _yy.ravel() top = x + y bottom = np.zeros_like(top) width = depth = 1 test_ax = test_fig.add_subplot(111, projection='3d') test_ax.bar3d(x, y, bottom, width, depth, top, shade=True, label='my label')
我尝试过以下方法:
- 执行
test_ax.zaxis.set_minor_locator(AutoMinorLocator()),并搭配以下修改尝试隐藏次要网格线:test_ax.zaxis._axinfo['grid']['minor'] = {'linewidth': 0}test_ax.zaxis._axinfo['grid']['minor'] = {'gridOn': False}
我尽量不想使用Matplotlib的受保护成员_axinfo,但目前也接受其他可行方法。
我的最新尝试代码:
test_ax.zaxis.set_minor_locator(AutoMinorLocator()) test_ax.zaxis.grid(visible=True, which='minor', alpha=0.0)
设置visible=True是因为设为False时没有任何变化,尝试修改linewidth等参数也无效。官方的zaxis.grid()文档不够完善,没有提供有效帮助。最新尝试后的绘图效果:
请问下一步该怎么做?
内容的提问来源于stack exchange,提问作者Python_Learner
相关产品推荐
相关产品推荐

