Python matplot画柱状图(一)
图的存在,让数据变得形象化。无论多么复杂的东西,都是简单的组合。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import matplotlib.pyplot as plt 2 import numpy as np 3 dict = {'A': 40, 'B': 70, 'C': 30, 'D': 85} 4 for i, key in enumerate(dict):#Circulate both index and value(Here is key) 5 plt.bar(i, dict[key], color='r', width=0.2) 6 plt.xticks(np.arange(len(dict))+0.1, dict.keys())#Translation 7 plt.yticks(dict.values()) 8 plt.grid(True) 9 plt.show()
运行结果: