[英]How to plot the distribution between 2 variables with Plotly Express (Python)?
我有一个数据框,看起来像这样,包含大约 20.000 行。
print(df)
>>>>
CUSTOMER_INCOME MARITAL_STATUS
50000 Relationship
65000 Single
17000 Single
120000 Relationship
42000 Relationship
56000 Single
(*MARITAL_STATUS 只有这两个变量:Relationship 和 Single)
我正在尝试使用情节来根据他们的“Marital_Status”可视化“客户收入”的分布。
下面的代码提供了这个图,但它看起来不正确。
px.scatter(df, x = 'Marital_Status', y = "Customer_Income")
如何以更合理的方式使用 plotly 根据他们的“Marital_Status”绘制“客户收入”的分布?
我认为您想在使用 px.histogram 时使用颜色选项。 我相信这可以解决您的问题:
fig = px.histogram(df, x="CUSTOMER_INCOME",color="MARITAL_STATUS",barmode="overlay")
请注意,这不会得到分布(分布总和为 1),但它会给你一个直方图。 如果您确实需要,请考虑查看https://plotly.com/python-api-reference/generated/plotly.express.histogram.html以了解 histnorm 选项是否对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.