【发布时间】:2020-11-14 05:27:44
【问题描述】:
我的 DataFrame 如下:-
spending advance_payments probability_of_full_payment current_balance credit_limit min_payment_amt max_spent_in_single_shopping
0 19.94 16.92 0.8752 6.675 3.763 3.252 6.550
1 15.99 14.89 0.9064 5.363 3.582 3.336 5.144
2 18.95 16.42 0.8829 6.248 3.755 3.368 6.148
3 10.83 12.96 0.8099 5.278 2.641 5.182 5.185
4 17.99 15.86 0.8992 5.890 3.694 2.068 5.837
... ... ... ... ... ... ... ...
205 13.89 14.02 0.8880 5.439 3.199 3.986 4.738
206 16.77 15.62 0.8638 5.927 3.438 4.920 5.795
207 14.03 14.16 0.8796 5.438 3.201 1.717 5.001
208 16.12 15.00 0.9000 5.709 3.485 2.270 5.443
209 15.57 15.15 0.8527 5.920 3.231 2.640 5.879
现在我正在尝试使用 seaborn 库在 displot 顶部绘制箱线图。 Distplot 本身工作正常,但是当我在同一轴上添加 boxplot 时,distplot 会倒置,不知道为什么会这样。有人可以帮我解决这个问题吗?
下面是我的代码:-
fig, axs = plt.subplots(3, 3,figsize=(10,10))
j=0
k=0
for i in df.columns:
sns.distplot(df[i],ax=axs[j,k],color='blue')
sns.boxplot(df[i],ax=axs[j,k],color='green',boxprops=dict(alpha=.5))
plt.gca().invert_xaxis()
k=k+1
if k==3:
k=0
j=j+1
fig.tight_layout()
plt.show()
我尝试过plt.gca().invert_xaxis(),但没有帮助。
下面是我得到的输出。
【问题讨论】:
标签: python matplotlib seaborn boxplot