如何在 python 中绘制条形图
How to plot bar graph in python
我在字典中有以下数据,想用标签 ('AT'、'BT'、'CT'、'DT'、'ET' 绘制条形图。只考虑小数点后3位就可以了
{0:0,
1:19.091883092036781,
2:35.317606562921746,
3:22.122563913375465,
4:37.961028320110699,
5: 36.541670802198659}
使用 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'))
我在字典中有以下数据,想用标签 ('AT'、'BT'、'CT'、'DT'、'ET' 绘制条形图。只考虑小数点后3位就可以了
{0:0, 1:19.091883092036781, 2:35.317606562921746, 3:22.122563913375465, 4:37.961028320110699, 5: 36.541670802198659}
使用 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'))