【问题标题】:How to plot bar graph in python如何在python中绘制条形图
【发布时间】:2016-07-06 00:56:35
【问题描述】:
我在字典中有以下数据,想用标签('AT','BT','CT','DT','ET')绘制条形图。只考虑小数点后三位即可。
{0:0,
1: 19.091883092036781,
2:35.317606562921746,
3:22.122563913375465,
4: 37.961028320110699,
5:36.541670802198659}
【问题讨论】:
标签:
python
matplotlib
matplotlib-basemap
matplotlib-widget
【解决方案1】:
使用 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'))