简体   繁体   中英

seaborn distplot different bar width on each figure

Sorry for giving an image however I think it is the best way to show my problem. 在此处输入图像描述

As you can see all of the bin width are different, from my understanding it shows range of rent_hours. I am not sure why different figure have different bin width even though I didn't set any.

My code looks is as follows:

figure, axes = plt.subplots(nrows=4, ncols=3)
figure.set_size_inches(18,14)
plt.subplots_adjust(hspace=0.5)

for ax, age_g in zip(axes.ravel(), age_cat):
    group = total_usage_df.loc[(total_usage_df.age_group == age_g) & (total_usage_df.day_of_week <= 4)]
    sns.distplot(group.rent_hour, ax=ax, kde=False)
    ax.set(title=age_g)
    ax.set_xlim([0, 24])

figure.suptitle("Weekday usage pattern", size=25);

additional question:

Seaborn: How to get the count in y axis for distplot using PairGrid for here it says that kde=False makes y-axis count however http://seaborn.pydata.org/generated/seaborn.distplot.html in the doc, it uses kde=False and still seems to show something else. How can I set y-axis to show count?

I've tried sns.distplot(group.rent_hour, ax=ax, norm_hist=True) and it still seems to give something else rather than count.

sns.distplot(group.rent_hour, ax=ax, kde=False) gives me count however I don't know why it is giving me count.

Answer 1:

From the documentation :

norm_hist : bool, optional

If True, the histogram height shows a density rather than a count. This is implied if a KDE or fitted density is plotted.

So you need to take into account your bin width as well, ie compute the area under the curve and not just the sum of the bin heights.

Answer 2:

# Plotting hist without kde
ax = sns.distplot(your_data, kde=False)

# Creating another Y axis
second_ax = ax.twinx()

#Plotting kde without hist on the second Y axis
sns.distplot(your_data, ax=second_ax, kde=True, hist=False)

#Removing Y ticks from the second axis
second_ax.set_yticks([])

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