You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Axes3D绘图的Z轴显示次要刻度但不显示次要网格线?

Axes3D绘图:显示Z轴次要刻度但隐藏次要网格线

我需要在Matplotlib的Axes3D绘图中显示Z轴的次要刻度,但不显示对应的次要网格线。

初始绘图效果:
sample Axes3D plot

初始代码:

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()文档不够完善,没有提供有效帮助。最新尝试后的绘图效果:
Axes 3D with minor ticks and gridlines

请问下一步该怎么做?


内容的提问来源于stack exchange,提问作者Python_Learner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 20:44:59