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

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

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

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

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

#**http://weibo.com/lixiaodaoaaa#

#**createat2017/5/2020:55***

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

frommatplotlib.font_managerimportFontManager,FontProperties

importsubprocess

importmatplotlib.pyplotasplot

defgetChineseFont():

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

if__name__=='__main__':

years=[2010,2011,2012,2013,2014,2015,2016,2017]

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

效果图如下:

?url=http%3A%2F%2Fdingyue.ws.126.net%2FeDITtv2PTJunjeBWEL0EnvGt8OZUdbXWu5JxCkeuZBtxP1521093781263.jpg&thumbnail=650x2147483647&quality=80&type=jpg

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

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

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

#**http://weibo.com/lixiaodaoaaa#

#**createat2017/5/2020:55***

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

frommatplotlib.font_managerimportFontManager,FontProperties

importsubprocess

importmatplotlib.pyplotasplot

defgetChineseFont():

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

if__name__=='__main__':

years=[2010,2011,2012,2013,2014,2015,2016,2017]

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

效果图如下

?url=http%3A%2F%2Fdingyue.ws.126.net%2FqT%3DygD9wHUEUjH6I9VRo7%3DphTjNWJ6T4D9BwmH3%3DQ5Y0D1521093781264.jpg&thumbnail=650x2147483647&quality=80&type=jpg

散点图

plot.scatter(years,gdps)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值