mplot3d 中的 z 轴格式

发布于 2024-11-18 17:34:25 字数 697 浏览 4 评论 0原文

我正在尝试在 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))

我在这里做错了什么?

I am trying to make a surface plot in matplotlib, but I am unable to make the formatting of the z-axis look good. I want it to be on scientific notation, with the prefix along the axis and the exponent above the axis (like what you usually get in matlab). At the moment I can only get the values without scientific notation (with a comma and five zeros in front), or I get the prefixes but not the exponent...

Try 1: (gives scientific notation, but not the exponent)

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)

Try 2: (gives the values on decimal form, same as default output)

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

What am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半枫 2024-11-25 17:34:25

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

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

When you create your ScalarFormatter, try the "use Math Text" parameter:

from matplotlib import ticker
niceMathTextForm = ticker.ScalarFormatter(useMathText=True)
ax.w_zaxis.set_major_formatter(niceMathTextForm)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文