python matplotlib绘制柏拉图pareto_如何用python制作Pareto图?

本文介绍了如何使用Python的matplotlib库创建Pareto图表。提供了两种方法,一种是绘制基本的Pareto图,另一种则按阈值分组,将超过阈值的部分归入'OTHERS'组。通过示例代码展示了如何计算累积百分比,并在图表中展示这些信息。
摘要由CSDN通过智能技术生成

ImportanceOfBeingErnest代码的更通用版本:def create_pareto_chart(df, by_variable, quant_variable):

df.index = by_variable

df["cumpercentage"] = quant_variable.cumsum()/quant_variable.sum()*100

fig, ax = plt.subplots()

ax.bar(df.index, quant_variable, color="C0")

ax2 = ax.twinx()

ax2.plot(df.index, df["cumpercentage"], color="C1", marker="D", ms=7)

ax2.yaxis.set_major_formatter(PercentFormatter())

ax.tick_params(axis="y", colors="C0")

ax2.tick_params(axis="y", colors="C1")

plt.show()

这一个也包括按阈值分组的Pareto。

例如:如果将其设置为70,则它会将70岁以上的少数民族分组为一个称为“其他”的组。def create_pareto_chart(by_variable, quant_variable, threshold):

total=quant_variable.sum()

df = pd.DataFrame({'by_var':by_variable, 'quan

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值