[英]seaborn distplot different bar width on each figure
正如您所看到的,所有的 bin 寬度都不同,據我了解,它顯示了rent_hours 的范圍。 我不確定為什么不同的圖形有不同的 bin 寬度,即使我沒有設置。
我的代碼如下所示:
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);
附加問題:
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使用 kde=False 並且似乎仍然顯示其他內容。 如何設置 y 軸以顯示計數?
我試過 sns.distplot(group.rent_hour, ax=ax, norm_hist=True) ,它似乎仍然給出了其他東西而不是計數。
sns.distplot(group.rent_hour, ax=ax, kde=False) 給我計數,但我不知道為什么它給我計數。
答案1:
從文檔中:
norm_hist : bool,可選
如果為 True,則直方圖高度顯示密度而不是計數。 如果繪制了 KDE 或擬合密度,則暗示這一點。
因此,您還需要考慮您的 bin 寬度,即計算曲線下的面積,而不僅僅是 bin 高度的總和。
答案 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([])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.