简体   繁体   中英

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

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.

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} . 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM