首页 > 解决方案 > 如何在matplotlib python上创建带有辅助y轴的分组条形图

问题描述

我刚开始学习和使用python。当我尝试使用辅助 y 轴创建分组条形图时遇到麻烦。

这是刚才的代码和结果

import matplotlib.pyplot as plt
fig, graph1=plt.subplots(figsize=(20,5))
graph2 = graph1.twinx()
graph1.bar(data_trans3['ITEM_NAME'],data_trans3['nett_profit'],width=0.3)
graph2.bar(data_trans3['ITEM_NAME'],data_trans3['QTY'],width=0.3)

在此处输入图像描述

我应该怎么做才能创建分组条形图,其中x 轴item_namey-primary 轴nett_profity-secondary 轴QTY

我确信上面的代码是一个简单的条形图的形式。

标签: pythonmatplotlib

解决方案


推荐阅读