先看画折线图观察两组数据的关联关系
我们举例,有两组数据,一组数据是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)