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

Matplotlib 3D曲面图Z轴缩放标签显示异常问题咨询

Matplotlib 3D曲面图Z轴缩放标签显示异常问题咨询

大家好,我遇到了一个Matplotlib 3D绘图的问题:当Z轴的数值变得很小的时候,轴上的量级显示不正确。

举个例子,我运行了下面这段代码:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib

print('matplotlib version : ', matplotlib.__version__)

X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
r = 0.0001 # scale z values 

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

# Plot the surface.
surf = ax.plot_surface(X, Y, r*Z, cmap=matplotlib.cm.coolwarm,
                       linewidth=0, antialiased=False)
                       
plt.show()

当我设置r=0.0001的时候,Z轴应该标注类似1e-5这样的量级才合理,但实际它用的刻度和我设置r=1时完全一样,没有自动调整量级。

编辑补充:我加上了实际生成的图,能看到Z轴的刻度完全没调整(我想要的是在轴上整体显示1e-5这样的量级,不是每个刻度都单独标)。

实际生成的图:
实际生成的3D曲面图Z轴刻度异常

如果把r设得极小,比如r=0.000000000000000000000001,我预期的图应该是这样的:
预期的3D曲面图Z轴刻度显示

备注:内容来源于stack exchange,提问作者twistedqbit

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 09:00:32