为什么在添加第二个y轴时matplotlib子图不显示x-tick标签?它仅显示最后一个子图的x-tick标签!当我评论ax2 = ax.twinx()时,它将显示x-tick标签,但我也需要第二个y-标签!
n_subplots=2
fig, axar = plt.subplots(n_subplots, 1,figsize=(10,8), dpi=100)
# fig.subplots_adjust(hspace=0.35, wspace=0.2)
df1 = pd.Series(np.random.rand(10))
df2 = pd.Series(np.random.rand(10))
for i in range(n_subplots):
ax = axar[i]
df1.plot(kind='bar', ax=ax)
ax.set_xticklabels((df1.index)*10)
ax2 = ax.twinx()
ax2.set_xticklabels((df1.index)*10)
ax2.set_ylim(bottom=0, top=10)
# df2.plot(kind='line', secondary_y=True, ax=ax2)