私はmatplotlibを使い始めましたが、私は小さな問題があります。私は3つのプロットを互いに重ねて重ねて、x軸と2つの異なるy軸を共有しようとしています。 これは私の現在のコードMatplotlib:xticksラベルが表示されない
import numpy as np
import matplotlib.pyplot as plt
periods = range(1,13)
n0 = [4.2, 6.7, 10.6, 51.3, 339, 45.6, 56.3, 112.9, 182.7, 185.7, 126.2, 25.39]
alp = [2.12, 2.14, 2.19, 2.35, 2.54, 2.33, 2.34, 2.43, 2.45, 2.46, 2.466, 2.249]
B = [0.045, 0.041, 0.04, 0.04, 0.057, 0.048, 0.044, 0.057, 0.054, 0.065, 0.06, 0.045]
emin = [166, 201.9, 215, 270.7, 351.8, 263.7, 302.2, 323.6, 328.7, 346.1, 279.5, 259.8]
emax = [21806, 28407, 5706, 22087, 17978, 11699, 19440, 17988, 26938, 14812, 14195, 26121]
eq = [7.8, 11.8, 13.3, 15.2, 8.87, 10.5, 13.8, 7.6, 11.5, 7.4, 6.4, 13.5]
f, (ax1, ax2, ax3) = plt.subplots(3, sharex = True)
ax1.scatter(periods, emin, c="k")
ax1.set_ylabel(r"$E_{min}")
ax1.yaxis.set_ticks(range(160, 380, 40))
ax4 = ax1.twinx()
ax4.scatter(periods, n0, c="r")
ax4.set_ylabel(r"$N_0$", color = 'r')
ax4.tick_params(colors = 'r')
ax4.yaxis.set_ticks(np.arange(20, 340, 50))
ax2.scatter(periods, emax, c="k")
ax2.set_ylabel(r"$E_{max}$")
ax2.yaxis.set_ticks(np.arange(5000, 30000, 5000))
ax5 = ax2.twinx()
ax5.scatter(periods, alpha, c="r")
ax5.set_ylabel("alp", color = 'r')
ax5.tick_params(colors = 'r')
ax5.yaxis.set_ticks(np.arange(2.1, 2.6, 0.1))
ax3.scatter(periods, eq, c="k")
ax3.set_ylabel("Eq")
ax3.yaxis.set_ticks(np.arange(6, 15, 2))
ax3.set_xlabel("Periods")
ax6 = ax3.twinx()
ax6.scatter(periods, B, c="r")
ax6.set_ylabel("B", color = 'r')
ax6.tick_params(colors = 'r')
ax6.yaxis.set_ticks(np.arange(0.02, 0.09, 0.02))
ax6.xaxis.set_ticks(range(1,13))
f.subplots_adjust(hspace = 0)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
plt.show()
であるが、x軸ラベルが表示されていません。ラベル自体(「期間」)は問題ありませんが、ダニは表示されません。私は行を変更しようとしました
ax6.xaxis.set_ticks(range(1,13))
他のすべての番号にもかかわらず、まだ動作しません。どんな助け? y軸のラベルを水平になるように90度回転させるにはどうすればいいですか?私はrotation = 90
をylabelに含めようとしましたが、変更されません(他の値は機能します)。
どうもありがとう
編集:私は消す場合TWINXは、それはあなたが最後の行に2つ目を変更する必要が表示されるようにダニやvisible = True
を設定し、あなたのxのために細かい
最後の2行目から..... 'visible = False'をチェックしてください。 – DavidG