【问题标题】:Histograms grouping by two criteria [python]按两个标准分组的直方图 [python]
【发布时间】:2017-06-07 00:55:12
【问题描述】:

我有一个这样的数据集:

我需要根据两个标准绘制这个数据集:Churn 和 Cust_Value。

我可以使用 seaborn 做到这一点:

sns.barplot(x="Cust_Value", y="value", hue="Churn", data=merged)
plt.show()

结果给了我:

如何将所有变量(值、年龄、重新加载、调用、持续时间、短信、gprs、非活动)添加到与条形组相同的图表中?

【问题讨论】:

  • 尝试融化数据,如图here

标签: python pandas histogram seaborn


【解决方案1】:

对于那种输出,我建议使用 plotly,

import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Bar(
    x=DF['Cust_Value'],
    y=DF['value'],
    name='value'
)
trace2 = go.Bar(
    x=DF['Cust_Value'],
    y=DF['age'],
    name='age'
)
trace3 = go.Bar(
    x=DF['Cust_Value'],
    y=DF['calls'],
    name='calls'
)

data = [trace1, trace2, trace3]
layout = go.Layout(
    barmode='group'
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='grouped-bar')

样本输出:

参考:https://plot.ly/python/bar-charts/

希望对你有帮助!

如果它确实支持:)

和平

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2017-08-28
    相关资源
    最近更新 更多