mplot3d中的z轴格式化

12
我正在尝试在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))

我在这里做错了什么?


1
你使用的是哪个版本的matplotlib?你可能遇到了一个bug,直到1.0.1才被修复。http://old.nabble.com/Displaying-offsets-in-3d-plots-td30474615.html - Stephen Terry
1
@Stephen Terry:我正在运行1.0.1版本。`Python 2.7.1 |EPD 7.0-2 (32-bit)| (r271:86832, Dec 3 2010, 15:41:32) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin
import matplotlib matplotlib.version '1.0.1'`
- Magnus
1个回答

4
当您创建ScalarFormatter时,请尝试使用“使用数学文本”参数:
from matplotlib import ticker
niceMathTextForm = ticker.ScalarFormatter(useMathText=True)
ax.w_zaxis.set_major_formatter(niceMathTextForm)

1
useOffset=false 对于科学计数法也很好。 - denfromufa

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接