Python 3.x 将元组列表绘制成直方图

Python 3.x 将元组列表绘制成直方图,python-3.x,matplotlib,Python 3.x,Matplotlib,我正在努力形成一个图表。 我有以下值的列表: [('1', 2434), ('10', 6792), ('11', 5214), ('12', 3354), ('2', 2854), ('3', 5571), ('4', 5602), ('5', 5768), ('6', 7320), ('7', 7341), ('8', 7198), ('9', 6878)] 对于元组的第一个值,值的范围从1到12,因为我处理的是月度数据 我用以下方法形成一个柱状图: lists = [('1', 2434

我正在努力形成一个图表。 我有以下值的列表:

[('1', 2434), ('10', 6792), ('11', 5214), ('12', 3354), ('2', 2854), ('3', 5571), ('4', 5602), ('5', 5768), ('6', 7320), ('7', 7341), ('8', 7198), ('9', 6878)]
对于元组的第一个值,值的范围从1到12,因为我处理的是月度数据

我用以下方法形成一个柱状图:

lists = [('1', 2434), ('10', 6792), ('11', 5214), ('12', 3354), ('2', 2854), ('3', 5571), ('4', 5602), ('5', 5768), ('6', 7320), ('7', 7341), ('8', 7198), ('9', 6878)]
x, y = zip(*lists) # unpack a list of pairs into two tuples

plt.hist(lists)
plt.title('Monthly Trends in Chicago City')
plt.xlabel('Monthly')
plt.ylabel('Rides')
plt.show()
这是前面代码生成的图表

非常感谢您的帮助

这就解决了问题

x, y = zip(*lists) # unpack a list of pairs into two tuples
x_months=['Jan', 'Oct', 'Nov', 'Dec', 'Feb', 'March', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept']

plt.bar(x_months, y, color='b')
plt.xticks(x_months, x_months, rotation='vertical')
plt.tight_layout()
plt.show()