绘图

自存


帕累托图

df=pd.read_excel('F:/Python/Python数据分析与业务应用实战/数据文件/b站订单/2月9日订单汇总.xlsx')

df=pd.DataFrame(df)

# 帕累托分析图

fig, ax1 = plt.subplots()

# 按数值大小排序

sorted_values, sorted_categories =zip(*sorted(zip(df_grouped['下单量'], df_grouped['下单时间']), reverse=True))

# 计算累计百分比

total =sum(sorted_values)

cumulative_percentages = [sum(sorted_values[:i +1]) / total *100 for iin range(len(sorted_values))]

plt.rcParams['font.sans-serif'] = ['SimHei']

ax1.bar(t, sorted_values, color='b')

for iin range(len(df_grouped['下单时间'])):

plt.text(i, sorted_categories[i] +1, str(sorted_categories[i]), ha='center', va='bottom')

ax1.set_ylabel('订单量')

ax2 = ax1.twinx()

ax2.plot(t, cumulative_percentages, 'r-o')

ax2.set_ylim([0, 100])

ax2.set_ylabel('累计百分比(%)')

plt.xticks(rotation=45)# 设置x轴标签旋转角度

ax1.legend(['订单量'], loc='upper left')

ax2.legend(['累计百分比'], loc='upper right')

plt.show()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容