开发者

z-axis formatting in mplot3d

开发者 https://www.devze.com 2023-03-18 15:23 出处:网络
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 exponen

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 th开发者_运维技巧e 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消