概述
1、柱状图import matplotlib.pyplot as plt
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、直方图import matplotlib as mpl
import matplotlib.pyplot as plt
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、阶梯图import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
year=range(2005,2020)
height=[168,155,182,170,173,161,155,173,176,181,166,172,170,180,187]
plt.step(year,height)
plt.show()
4、折线图import matplotlib.pyplot as plt
year=range(2005,2020)
height=[168,155,182,170,173,161,155,173,176,181,166,172,170,180,187]
plt.plot(year,height)
plt.show()
5、饼图import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#支持中文标题
labels=['房贷','饮食','出行','教育']
data=[8000,2000,2000,3000]
plt.pie(data,labels=labels,autopct='%1.1f%%')
plt.show()
最后
以上就是俊逸鞋垫为你收集整理的python画饼图柱状图_python库之matplotlib的柱状图、直方图、阶梯图、折线图、饼图...的全部内容,希望文章能够帮你解决python画饼图柱状图_python库之matplotlib的柱状图、直方图、阶梯图、折线图、饼图...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复