我在字典中有以下数据,想要用标签绘制条形图(' AT',' BT',' CT',' DT&# 39;,' ET&#39)。如果只考虑十进制后的3位数就可以了。
{0:0, 1:19.091883092036781, 2:35.317606562921746, 3:22.122563913375465, 4:37.961028320110699, 5:36.541670802198659}
答案 0 :(得分:3)
尝试使用matplotlib:
import matplotlib.pyplot as plt
data = {0: 0, 1: 19.091883092036781, 2: 35.317606562921746, 3: 22.122563913375465, 4: 37.961028320110699, 5: 36.541670802198659}
bar_width = 0.8
plt.bar([x for x in data], [data[x] for x in data], bar_width)
plt.xticks([x + bar_width/2 for x in data], (' ', 'AT','BT','CT','DT','ET'))