在python中使用dictionary作为matplotlib的参数

2024-10-01 13:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

在plotule中如何使用键值而不是键值

tuple=(1,2,3,4)
rects1 = ax.bar(ind, tuple, width, color='r')

但我想这样做

^{pr2}$

Tags: baraxwidthcolor键值indtuplepr2
2条回答

我猜你想做这样的事

rects1 = ax.bar(ind, (dic[k] for k in ind), ...)

这样在索引和字典中的值之间有一个映射。在

试试这个:

rects1 = ax.bar(ind, (dic[key] for key in dic.keys()), width, color='r')

甚至:

^{pr2}$

根据Amars的评论,如果dict是这样的:

dic={'a':(1,2),'b':(2,2),'c':(3,2)}

并且您只想使用值(1, 2, 3),您需要创建一个有序集:

rects1 = ax.bar(ind, sorted(set(dic.values())), width, color='r')

相关问题 更多 >