我正在尝试在 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))
我在这里做错了什么?
最佳答案
当您创建 ScalarFormatter
时,尝试使用“使用数学文本”参数:
from matplotlib import ticker
niceMathTextForm = ticker.ScalarFormatter(useMathText=True)
ax.w_zaxis.set_major_formatter(niceMathTextForm)
关于python - mplot3d 中的 z 轴格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596583/