mplot3d 中的 z 轴格式
我正在尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建
ScalarFormatter
时,尝试“使用数学文本”参数:When you create your
ScalarFormatter
, try the "use Math Text" parameter: