対数の x 軸と y 軸を持つ散布図があります (両方の低い値に主に関心があるため)。
ただし、目盛りラベルを 10^x ではなく 10 進数形式にしたいと考えています。
私はこれを使用しています:
# axis limits:
ax.set_xlim(xmin=0, xmax = 1.2)
ax.set_ylim(ymin=0,ymax=1000)
# log scales:
ax.set_yscale('log')
ax.set_xscale('log')
# set y-ticks:
ax.set_yticks((1,10,100,1000))
ax.set_yticklabels(("1","10","100","1000"))
これは機能します (ただし、次の警告が表示されるax.set_yscale('log')
かax.set_xscale('log')
、表示されます (何が起こっているのか分かりますか?)):
Warning (from warnings module):
File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3785
warnings.warn("Warning: converting a masked element to nan.")
UserWarning: Warning: converting a masked element to nan.
しかし、x 軸に対して同じことを試みると、MaskError が発生します。
# set x-ticks:
ax.set_xticks((0, 0.2, 0.4, 0.8, 1))
ax.set_xticklabels(("0", "0.2", "0.4", "0.8", "1"))
[snip long long traceback]
File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3795, in __int__
raise MaskError, 'Cannot convert masked element to a Python int.'
MaskError: Cannot convert masked element to a Python int.
マイナーティックとメジャーティックに関係があると思います。ティッカーをいじってみましたが、最後にはいつも同じエラーが発生します。
私はどんな助けにも非常に感謝しています!
回答後に編集: 置き換えて解決した問題
ax.set_yticks((1,10,100,1000))
ax.set_yticklabels(("1","10","100","1000"))
ax.set_xticks((0, 0.2, 0.4, 0.8, 1))
ax.set_xticklabels(("0", "0.2", "0.4", "0.8", "1"))
と
ax.yaxis.set_major_formatter(FormatStrFormatter('%1.0f'))
ax.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
ax.xaxis.set_minor_formatter(FormatStrFormatter('%.1f'))