如何更改海洋直方图中的y轴限制?

时间:2019-12-13 14:58:20

标签: python pandas seaborn

我的原始数据高度不平衡,看起来像:

df
Index Branch
1      10000
2        200
...
1000   1
...
10000  1

如果我跑步:

import seaborn as sns
sns.distplot(df['Branch'], bins=1000)

结果如下:

enter image description here

是否有机会将可视化中的y值最大值固定为0.06?并将x值调整为1000左右。

1 个答案:

答案 0 :(得分:1)

seaborn在引擎盖下使用matplotlib,因此您可以

import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot(df['Branch'], bins=1000)
plt.ylim(0, 0.06)

与x轴相同:

plt.xlim(0, 500)

还有通常的plt.show()可以使不需要的打印输出静音:Out[60]: (0, 0.4)

编辑:是,它不会更改曲线或曲线下方的区域。它仅更改“图片”的边界。我进行了测试,您可以在下面看到累积分布曲线是在数据的尺度上,而不是在 image 的尺度上。如果是这样,则累积线(橙色)将在图像右侧达到100%。我通过添加kde_kws={'cumulative':True}来做到这一点。 enter image description here

相关问题