Pythonを使用して、科学の表記法で表示する軸の目盛りのラベルを取得しようとしています。ax1.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2E'))
(完全なコード)matplotlib format_major_ticks軸の目盛りのラベルを取得しない
これは、以前に設定された目盛ラベルを無視して、図1に示すようにrange(len(axis_vector))
を科学表記でフォーマットします。ax1.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2E'))
を使用しないで、科学的表記では表示されません。図2.
図1
図2:
は、どのように私はそれが科学表記法で、実際の目盛りラベルを表示するために得ることができますか?ここ
は、ランダムに生成されたサンプルデータとコードである:ダニフォーマッタは、ダニ値ない以前のラベルに直接動作するため
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import matplotlib.ticker as mtick
y = np.array([1E0,5E0,1E1,5E1,1E2,5E2,1E3,5E3,1E4,5e4,1E5,5E5,1E6,5E5,1E7,5E7])
x = np.arange(0.2,3.2,0.2)
### generate sample data with random powers of 10
data = np.zeros(240)
for i in range(len(data)):
power = np.round(np.random.rand()*10)
data[i] = 10**power
image = data.reshape((16,15))
### Plotting
fig = plt.figure(figsize=(6,6))
ax1 = fig.add_subplot(111)
im = ax1.imshow(image, interpolation='none',norm=LogNorm(vmin=(np.min(image)),vmax=(np.max(image))))
ax1.set_xticks(np.arange(len(x)), minor=False)
ax1.set_xticklabels(x, minor=False)
ax1.set_xlabel('x-axis')
ax1.set_yticks(np.arange(len(y)), minor=False)
ax1.set_yticklabels(y, minor=False)
ax1.set_ylabel('y-axis')
ax1.tick_params(labelbottom='on',labeltop='off', labelleft='on',labelright='off',
top='off', right='off')
ax1.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2E'))
axcolor = fig.add_axes([0.9, 0.12, 0.03, 0.79])
t = np.logspace(1,11,num=12)
fig.colorbar(im, cax=axcolor, ticks=t, format='%.3E')