300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python在直方图上画折线图_python库之matplotlib的柱状图 直方图 阶梯图 折线图 饼图...

python在直方图上画折线图_python库之matplotlib的柱状图 直方图 阶梯图 折线图 饼图...

时间:2022-08-03 18:56:48

相关推荐

python在直方图上画折线图_python库之matplotlib的柱状图 直方图 阶梯图 折线图 饼图...

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()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。