python - mplot3d 中的 z 轴格式

标签 python matplotlib mplot3d

我正在尝试在 matplotlib 中绘制曲面图,但我无法使 z 轴的格式看起来不错。我希望它采用科学记数法,轴上有前缀,轴上有指数(就像你通常在 matlab 中得到的那样)。目前我只能得到没有科学记数法的值(前面有一个逗号和五个零),或者我得到的是前缀而不是指数......

尝试 1:(给出科学记数法,但不给出指数)

from matplotlib import ticker

ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=3, cstride=3)
formatter = ticker.ScalarFormatter()
formatter.set_scientific(True)
formatter.set_powerlimits((-2,2))
ax.w_zaxis.set_major_formatter(formatter)

尝试 2:(给出十进制形式的值,与默认输出相同)

from matplotlib import ticker

ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=3, cstride=3)
ax.ticklabel_format(axis="z", style="sci", scilimits=(0,0))

我在这里做错了什么?

最佳答案

当您创建 ScalarFormatter 时,尝试使用“使用数学文本”参数:

from matplotlib import ticker
niceMathTextForm = ticker.ScalarFormatter(useMathText=True)
ax.w_zaxis.set_major_formatter(niceMathTextForm)

关于python - mplot3d 中的 z 轴格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596583/

相关文章:

python - 如何将pandas时间序列图中的xticks更改为每年间隔

python - Visual Studio Code : "matplotlib" is not accessed Pylance

python - 计算并绘制 (Y) 总计列表中每 (X) 项的平均值

python - 如何使用 matplotlib/mplot3d 绘制 3D 直方图?

python - 如何禁用 mplot3d 中的透视图?

python - Google App Engine ndb 查询

python - 使用 python+perforce 的 undefined symbol TLSv1

python - 查找所有文件间接目录和子目录并提供目录的路径

python - 如何在基于外部查询的子查询中创建条件?

python - MatplotLib 3.0.1 中 ax.set_xlabel() 和 ax.xaxis.set_label() 的区别