1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python 柱状图和折线图放在一起_python中用matplotlib画折线图 柱状图 散点图

python 柱状图和折线图放在一起_python中用matplotlib画折线图 柱状图 散点图

时间:2023-03-10 06:02:05

相关推荐

python 柱状图和折线图放在一起_python中用matplotlib画折线图 柱状图 散点图

先看画折线图观察两组数据的关联关系

我们举例,有两组数据,一组数据是dgp一组是对应的年份。那么我们可以画出年份与GDP的关系图,是上升还是下降来来来看代码。

#-*-coding:utf-8-*-

#**********************************

#**/lixiaodaoaaa#

#**createat/5/:55***

#******by:lixiaodaoaaa***********

frommatplotlib.font_managerimportFontManager,FontProperties

importsubprocess

importmatplotlib.pyplotasplot

defgetChineseFont():

returnFontProperties(fname='/System/Library/Fonts/PingFang.ttc')

if__name__=='__main__':

years=[,,,,,,,]

gdps=[256,289,302,356,389,400,402,436]

plot.ylabel('gdp指标')

plot.xlabel("年份")

plot.plot(years,gdps,color='red',marker='o',line)

plot.title('年份与GDP的关系图',fontproperties=getChineseFont())

plot.show()

效果图如下:

同样的我们可以画一个柱状图:

#-*-coding:utf-8-*-

#**********************************

#**/lixiaodaoaaa#

#**createat/5/:55***

#******by:lixiaodaoaaa***********

frommatplotlib.font_managerimportFontManager,FontProperties

importsubprocess

importmatplotlib.pyplotasplot

defgetChineseFont():

returnFontProperties(fname='/System/Library/Fonts/PingFang.ttc')

if__name__=='__main__':

years=[,,,,,,,]

gdps=[256,289,302,356,389,400,402,436]

plot.ylabel('gdp指标',fontproperties=getChineseFont())

plot.xlabel("年份",fontproperties=getChineseFont())

#plot.plot(years,gdps,color='red',marker='o',line)

plot.title('年份与GDP的关系图',fontproperties=getChineseFont())

plot.bar(years,gdps)

plot.show()

效果图如下

散点图

plot.scatter(years,gdps)

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