我正在使用seaborn繪制圖形,代碼是:
fig, ax = plt.subplots(figsize=(20, 10))
ax2 = ax.twinx()
sns.barplot(x="dt_mvtc", y="qtde_t0",
data=df_grafico_merge.query('t0_def_qtt==1'),color='blue',ax=ax)
sns.lineplot(x="dt_mvtc",y='qtde_t12', hue='t12_def_qtt', style='t12_def_qtt',
data=df_grafico_merge.query('t0_def_qtt==1'),markers= True, color='orange', ax=ax2)
plt.xlabel("Data")
plt.ylabel("Quantidade")
plt.title('Qtde de registros por data e t0=1')
plt.xticks(rotation=90)
for axis in [ax.yaxis]:
formatter = ScalarFormatter()
formatter.set_scientific(True)
axis.set_major_formatter(formatter)
plt.show()
輸出是:

為什么x軸是這樣的?既然我都在使用x=dt_mvtc,為什么他們混合?只是為了比較,當我注釋該行時ax2 = ax.twinx(),軸輸出正確(即,日期旋轉 90 度且可讀),所以我的問題是使用twinx(),但我不知道哪里出錯了。有什么幫助嗎?
uj5u.com熱心網友回復:
plt.xticks僅使用被呼叫的最后一個子圖軸。要獲得旋轉的 xticks 添加:
for ax_ in fig.axes:
plt.sca(ax_)
plt.xticks(rotation=90)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/335146.html
標籤:matplotlib 海生 双胞胎
上一篇:mpld3.show()回傳型別為int的物件不是JSON可序列化的
下一篇:具有不同線條樣式的熊貓繪圖線?
