我有以下 playbook ,但第二组的结果情节被第一组歪曲了.

labels = ['CA',  'ME']
Addmitted = [500000, 100]
Applied = [10000000, 1000]

x = np.arange(len(labels))  
width = 0.35  

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, Addmitted, width, label='Admitted')
rects2 = ax.bar(x + width/2, Applied, width, label='Applied')

ax.set_xticks(x, labels)
ax.legend()

ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)

fig.tight_layout()
plt.ylim(0, 12000000)

plt.show()

enter image description here

推荐答案

I am posting as an answer but there is probably a better way to do this:

labels = ['CA',  'ME']
Addmitted_l = [500000, 0]
Applied_l = [10000000, 0]

Addmitted_r = [0, 120]
Applied_r = [0, 300]

x = np.arange(len(labels))  
width = 0.2  

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, Addmitted_l, width, label='Admitted')
rects2 = ax.bar(x + width/2, Applied_l, width, label='Applied')

ax2 = ax.twinx()
rects3 = ax2.bar(x - width/2, Addmitted_r, width, label='Admitted')
rects4 = ax2.bar(x + width/2, Applied_r, width, label='Applied')

ax.set_xticks(x, labels)
ax2.legend(loc='upper center')

ax.ticklabel_format(style='plain', axis='y')
fig.tight_layout()

plt.show()

enter image description here

Python相关问答推荐

两极按组颠倒顺序

取相框中一列的第二位数字

合并其中一个具有重叠范围的两个框架的最佳方法是什么?

pyramid 内部数组中的连续序列-两极

阅读Polars Python中管道的函数定义

覆盖Django rest响应,仅返回PK

当密钥是复合且唯一时,Pandas合并抱怨标签不唯一

如果条件为真,则Groupby.mean()

对整个 pyramid 进行分组与对 pyramid 列子集进行分组

删除所有列值,但判断是否存在任何二元组

使可滚动框架在tkinter环境中看起来自然

将图像拖到另一个图像

在极性中创建条件累积和

提取相关行的最快方法—pandas

计算分布的标准差

从嵌套的yaml创建一个嵌套字符串,后面跟着点

SQLAlchemy bindparam在mssql上失败(但在mysql上工作)

如何从列表框中 Select 而不出错?

Python全局变量递归得到不同的结果

python panda ExcelWriter切换动态公式到数组公式