私は、matplotlib.pyplot で対数プロットを使用しており、x 軸は数桁しか変化しません。主要な目盛りのみにラベルを付けると、x 軸は非常にまばらで少し不明瞭に見えます。小目盛りにもラベルを付けるにはどうすればよいですか?
1928 次
2 に答える
2
小目盛ラベルに何を付けますか? 軸をもう少し生き生きと見せたいだけなら、
import numpy as np
from matplotlib.ticker import LogLocator, FormatStrFormatter
# display 5 minor ticks between each major tick
minorLocator = LogLocator(subs=np.linspace(2,10,6,endpoint=False))
# format the labels (if they're the x values)
majorFormatter = FormatStrFormatter('%5.4f')
# for no labels use default NullFormatter
ax.xaxis.set_minor_locator(minorLocator)
# or if you want to see some constrained floats
# this may make things busy!
ax.xaxis.set_minor_formatter(minorFormatter)
于 2013-05-30T12:50:36.457 に答える
1
私は次のようなことをします:
plt.xticks([1, 3, 10, 30, 100, 300], [1, 3, 10, 30, 100, 300])
これはおそらく、現在の軸の範囲を取得し、目盛りと目盛りラベルの適切なシーケンスを生成する便利な関数に入れる必要があります。
このようなことを行うmatplotlibの「Ticker」オブジェクトがあるかもしれません。残念ながら、ログ プロットに関するドキュメントはかなりまばらです。
于 2013-05-30T07:55:09.083 に答える