简体   繁体   English

mplot3d中的z轴格式

[英]z-axis formatting in mplot3d

I am trying to make a surface plot in matplotlib, but I am unable to make the formatting of the z-axis look good.我正在尝试在 matplotlib 中制作表面 plot,但我无法使 z 轴的格式看起来不错。 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).我希望它采用科学记数法,前缀沿轴,指数在轴上方(就像您通常在 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)尝试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)

Try 2: (gives the values on decimal form, same as default output)尝试 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))

What am I doing wrong here?我在这里做错了什么?

When you create your ScalarFormatter , try the "use Math Text" parameter:创建ScalarFormatter时,请尝试“使用数学文本”参数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM