1、柱状图importmatplotlib.pyplotasplt
plt.rcParams['font.sans-serif']=['SimHei']#支持中文标题
classes=['class1','class2','class3']
scores=[70,80,60]
name=['A班','B班','C版']
plt.bar(classes,scores)
plt.title('三班成绩柱状图')
plt.xlabel('班级')
plt.ylabel('成绩')
plt.xticks(classes,name)
plt.text('class1',71,70)
plt.text('class2',81,80)
plt.text('class3',61,60)
plt.show()
2、直方图importmatplotlibasmpl
importmatplotlib.pyplotasplt
height=[168,155,182,170,173,161,155,173,176,181,166,172,170]
bins=range(150,191,5)#从150到191,步长为5
plt.hist(height,bins=bins)
plt.show()
3、阶梯图importmatplotlib.pyplotasplt
plt.rcParams['font.sans-serif']=['SimHei']
year=range(,)
height=[168,155,182,170,173,161,155,173,176,181,166,172,170,180,187]
plt.step(year,height)
plt.show()
4、折线图importmatplotlib.pyplotasplt
year=range(,)
height=[168,155,182,170,173,161,155,173,176,181,166,172,170,180,187]
plt.plot(year,height)
plt.show()
5、饼图importmatplotlib.pyplotasplt
plt.rcParams['font.sans-serif']=['SimHei']#支持中文标题
labels=['房贷','饮食','出行','教育']
data=[8000,2000,2000,3000]
plt.pie(data,labels=labels,autopct='%1.1f%%')
plt.show()