【发布时间】:2016-08-09 13:05:38
【问题描述】:
我正在尝试使用 matplotlib 使用 2 个具有完全相同键的不同字典在条形图中绘制 2 个轴。 我无法确保两个字典的项目(键和值)的顺序相同。
代码示例:
ind = numpy.arange(len(types_dict)) # the x locations for the groups
fig, ax = plt.subplots()
rects1 = ax.bar(ind, types_dict.values(), 0.35, color='green')
rects2 = ax.bar(ind+0.35, genome_types_dict.values(), 0.35, color='purple')
plt.xticks(ind+width, types_dict.keys(), fontsize=10)
plt.savefig(output+"bar_" + library_name + ".png")
打印字典 types_dict 和基因组_types_dict 的键时,它们的键不按顺序排列,因此它们的值也不按顺序排列:
types_dict = ['rRNA', 'IGR', '3UTR', 'sRNA', 'tRNA', 'TU', '5UTR', 'AS', 'cis_AS_with_trans_t', 'mRNA', 'other-ncRNA']
genome_types_dict = ['rRNA', 'IGR', '3UTR', '5UTR', 'tRNA', 'TU', 'sRNA', 'AS', 'cis_AS_with_trans_t', 'mRNA', 'other-ncRNA']
寻找两个字典之间对齐的解决方案。
谢谢,
【问题讨论】:
标签: python dictionary matplotlib bar-chart