11

matplotlib でサーフェス プロットを作成しようとしていますが、z 軸の書式設定を適切に行うことができません。軸に沿って接頭辞を付け、軸の上に指数を付けて科学的記法にしたいと思います(通常、matlabで得られるように)。現時点では、科学表記法なしで値を取得することしかできません (コンマと 5 つのゼロを前に付けて)、または接頭辞は取得できますが、指数は取得できません...

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 を試してください: (デフォルトの出力と同じ 10 進形式で値を返します)

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

ここで何が間違っていますか?

4

1 に答える 1

3

を作成するときはScalarFormatter、「use Math Text」パラメーターを試してください。

from matplotlib import ticker
niceMathTextForm = ticker.ScalarFormatter(useMathText=True)
ax.w_zaxis.set_major_formatter(niceMathTextForm)
于 2011-07-24T22:30:01.640 に答える