我有一個資料框
A B C
3 4 0.425744 62244
2 3 0.351339 61479
1 2 0.221772 62677
0 1 0.204175 63181
使用欄位Cforbarplot和Bin lineplot,
#code of plot
fig, ax1 = plt.subplots(1,1,figsize=(6,4))
sns.lineplot(data = af['B'], marker='o', ax=ax1,)
ax2 = ax1.twinx()
sns.barplot(data = af, x='A',y="C" , alpha=0.5, ax=ax2)

我想根據折線圖對值進行排序。在我們的例子中,序列應該是 4-3-2-1。
uj5u.com熱心網友回復:
如果我理解正確:
轉換
A為str:af['A'] = af['A'].astype(str)而不是
data=af['B'],af用作data源x='A':sns.lineplot(data=af, x='A', y='B', marker='o', ax=ax1)
代碼和輸出:
af['A'] = af['A'].astype(str)
fig, ax1 = plt.subplots(1,1,figsize=(6,4))
sns.lineplot(data=af, x='A', y='B', marker='o', ax=ax1)
ax2 = ax1.twinx()
sns.barplot(data=af, x='A', y='C', alpha=0.5, ax=ax2)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/345396.html
標籤:Python matplotlib 海生
上一篇:資料型別上的Haskell多型性
