python开发中用matplotlib画折线图、柱状图、散点图代码详解

2018-03-15 14:06:29 1746浏览

今天我们举例,有两组数据,一组数据是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',linestyle='solid')

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

plot.show()

效果图如下:


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

#-*-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',linestyle='solid')

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

plot.bar(years,gdps)

plot.show()

效果图如下


散点图

plot.scatter(years,gdps)



以上就是关于扣丁学堂Python培训之用matplotlib画折线图、柱状图、散点图的详细介绍,最后想要了解更多关于Python发展前景趋势,请关注扣丁学堂python培训官网、微信等平台,扣丁学堂IT职业在线学习教育平台为您提供最新的Python视频教程系统,通过千锋扣丁学堂金牌讲师在线录制的Python视频教程课程,让你快速掌握Python从入门到精通开发实战技能。扣丁学堂Python开发工程师技术交流群:279521237。


扣丁学堂微信公众号



关注微信公众号获取更多学习资料



查看更多关于"Python开发资讯"的相关文章>>


标签: Python视频教程 Python基础教程 Python爬虫 Python培训 Python开发工程师

热门专区

暂无热门资讯

课程推荐

微信
微博
15311698296

全国免费咨询热线

邮箱:codingke@1000phone.com

官方群:148715490

北京千锋互联科技有限公司版权所有   北京市海淀区宝盛北里西区28号中关村智诚科创大厦4层
京ICP备12003911号-6   Copyright © 2013 - 2019

京公网安备 11010802030908号