在酒吧从字典中订购字符串标签

2024-03-29 01:26:11 发布

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

我正在写一个脚本,它将从字典中产生一个条形图。我知道字典里的条目通常是无序的。有没有什么方法可以仅仅为了条形图而订购呢?你知道吗

cats=dict((x, events.count(x)) for x in events)
fig=plt.figure()
fig.suptitle("HEALTH records", fontsize=15, fontweight='bold')
ax=fig.add_subplot(111)

ax.set_title("Number of records {0}, collected on {1} animals".format(len(events), len(anims)), fontsize=10)

ax.bar(range(len(cats)), cats.values())
plt.xticks(range(len(cats)), cats.keys())
locs, labels = plt.xticks()
ax.set_xlabel("Health codes")
ax.set_ylabel("Counts")
plt.savefig("HEALTH records {0}.png".format(pop))
plt.clf()

current graph


Tags: formatlen字典figrangepltaxevents