python - seaborn distplot 每个图上不同的条形宽度
问题描述
正如您所看到的,所有的 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 kde=False 使 y-axis count 然而http://seaborn.pydata.org/generated/seaborn.distplot.html在文档中,它使用 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([])
推荐阅读
- docker - Azure Pipeline Angular Build Docker Image 失败
- redux - 当 Redux 状态更改时,React 组件表不会重新渲染
- python - 如何根据 django 中的相同键值将列表转换为 json
- android - 打开键盘时按钮不出现
- reactjs - 反应原生:标题标志,标题和底部导航
- unit-testing - Chef rspec - 如何处理 open.file?
- java - imageView.setVisibility(View.GONE); 不适用于 ImageView
- docker - 如何从 docker 容器中捕获应用程序监控信息
- sql - 如何检查浮点数后real是否有任何数字
- python - 尝试创建 conda 环境时 ResolvePackageNotFound