How do I change y-axis limits in seaborn histogram?

╄→гoц情女王★ 提交于 2021-01-07 01:59:40

问题


I have highly imbalanced raw data, which looks like:

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

And if I run:

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

The outcome looks like this:

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.


回答1:


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)

Same for x-axis:

plt.xlim(0, 500)

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

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}.



来源:https://stackoverflow.com/questions/59325022/how-do-i-change-y-axis-limits-in-seaborn-histogram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!