为什么使用 sns seaborn 和 stack 时直方图之间有空格[重复]

问题描述 投票:0回答:1

(https://i.stack.imgur.com/UoTLJ.png)

我尝试使用 sns seaborn 和 stack 做直方图,但为什么直方图之间有一些空白?

这是我的代码,不起作用:

sns.histplot(data=airline_df, x="age", hue="customer_type", multiple="stack")
python-3.x seaborn data-science visualization
1个回答
1
投票
import seaborn as sns

# If you suspect the data is discrete and want to treat it as such
sns.histplot(data=airline_df, x="age", hue="customer_type", multiple="stack", discrete=True)

# If you want to manually specify bin width
sns.histplot(data=airline_df, x="age", hue="customer_type", multiple="stack", binwidth=5)

# If you want to specify custom bin edges
bin_edges = [0, 18, 30, 40, 50, 60, 70, 80, 90, 100]  # Example bin edges
sns.histplot(data=airline_df, x="age", hue="customer_type", multiple="stack", bins=bin_edges)
© www.soinside.com 2019 - 2024. All rights reserved.