如何使用 plt.bar 为每个字典键绘制元组或值列表

How to plot a tuple or list of values for each dictionary key using plt.bar

我已经知道 this question 并且它运行良好,但字典的每个键中只有一个值。因此,例如这有效:

dictionary = {'group_1': 50, 'group_2': 70, 'group_3': 80}

但我想要的是为每个键使用两个值绘制一个条形图,以便我可以并排比较:

dictionary = {'group_2': (50, 60), 'group_2': (70, 40), 'group_3': (80, 20)}

如果我尝试使用这些值绘制条形图,我会得到

ValueError: shape mismatch: objects cannot be broadcast to a single shape

这就是我想要的那种图表

看这里:plt.bar。你有 index 的地方你 select 字典中的键。然后 index, 'means_frank' 之后的第二个元素可以是第一个或 n 字典中的切片(前两个值)。