如何更改 seaborn 直方图中的 y 轴限制? [英] How do I change y-axis limits in seaborn histogram?

查看:193
本文介绍了如何更改 seaborn 直方图中的 y 轴限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have highly imbalanced raw data, which looks like:

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

如果我跑:

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

结果如下:

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

Is there any chance to fix the maximum of the y-value in the visualization to 0.06? And to adjust the x-value to 1000 or something.

推荐答案

seaborn 在幕后使用 matplotlib 所以你可以

seaborn uses matplotlib under the hood so you can just

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)

Also the usual plt.show() to mute the undesired printout: Out[60]: (0, 0.4)

是的,它不会改变曲线或曲线下方的面积.它只会改变图片"的边界.我做了测试,你可以在下面看到累积分布曲线在数据的范围内,而不是图像.如果是这样,累积线(橙色)将在图像右侧达到 100%.我通过添加 kde_kws={'cumulative':True} 来做到这一点.

EDIT : Yes, it doesn't change the curve or the area under it. It only changes the boundaries of the "picture". I made the test, you can see below that the cumulative distribution curve is on the scale of the data, and not the image. If it did, the cumulative line (orange) would have reached 100% at the right of the image. I did this by adding kde_kws={'cumulative':True}.

这篇关于如何更改 seaborn 直方图中的 y 轴限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆