简体   繁体   中英

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. 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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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