0
私のx軸は両方ともログスケールです。上側のx軸は下側の軸(この例では2乗)の関数です。双対対数軸の目盛りのラベルを10の累乗として表示するにはどうすればよいですか?
下軸の目盛りラベルが自動的に10の累乗でフォーマットされていますが、上部の軸がある別のデフォルトのフォーマット(科学的表記):
どのように私はこの問題を解決するのですか?
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
x = np.logspace(-9,0,10)
x2 = x**2
new_tick_locations = x[3:-3]
new_tick_labels = x2[3:-3]
y = np.ones(np.size(x))
ax1.semilogx(x,y)
plt.grid(True)
ax1.set_xlabel(r"Original x-axis: $X$")
ax2.set_xscale('log')
ax2.set_xlim(ax1.get_xlim())
ax2.set_xticks(new_tick_locations)
ax2.set_xticklabels(new_tick_labels)
ax2.set_xlabel(r"Modified x-axis: $X^2$")
plt.show()