折线图——matplotlib

# %load distanceTrans.py

import matplotlib.pyplot as plt

from matplotlib.pyplot import MultipleLocator

import matplotlib.patches as mpatches

import numpy as np

reservoirDis=np.random.randn(17)

reservoirArea=np.random.randn(17)

riverDis=np.random.randn(17)

riverArea=np.random.randn(17)

lakeDis=np.random.randn(17)

lakeArea=np.random.randn(17)

cannelDis=np.random.randn(17)

cannelArea=np.random.randn(17)

year=[2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017]

#labels=['2001-2002','2002-2003','2003-2004','2004-2005','2005-2006','2006-2007','2007-2008','2008-2009','2009-2010','2010-2011','2011-2012','2012-2013','2013-2014','2014-2015','2015-2016','2016-2017','2017-2018']

plt.figure(figsize=(20,15))

#第一个图表

plt.subplot(221)

plt.plot(year,riverDis,c='b',marker='^',linewidth=2)

plt.plot(year,riverArea,c='r',marker='^',linewidth=2)

#设置图表标题,并给坐标轴加上标签

plt.title(u"(a)1",fontsize=20)

plt.xlabel("Year", fontsize=16)

#设置刻度标记的大小

plt.tick_params(axis='both', labelsize=12)

x_major_locator=MultipleLocator(2)

#把x轴的刻度间隔设置为1,并存在变量里

ax=plt.gca()

#ax为两条坐标轴的实例

ax.xaxis.set_major_locator(x_major_locator)

#把x轴的主刻度设置为1的倍数

ax.set_xticklabels(labels=['2001-2002','2002-2003','2003-2004','2004-2005','2005-2006','2006-2007','2007-2008','2008-2009','2009-2010','2010-2011','2011-2012','2012-2013','2013-2014','2014-2015','2015-2016','2016-2017','2017-2018'],rotation=320)

plt.legend(labels = ['normalization1', 'normalization2'], loc = 'best',fontsize=20)

#第二个图表

plt.subplot(222)

plt.plot(year,lakeDis,c='b',marker='^',linewidth=2)

plt.plot(year,lakeArea,c='r',marker='^',linewidth=2)

#设置图表标题,并给坐标轴加上标签

plt.title(u"(b)2",fontsize=20)

plt.xlabel("Year", fontsize=16)

#设置刻度标记的大小

plt.tick_params(axis='both', labelsize=12)

x_major_locator=MultipleLocator(2)

#把x轴的刻度间隔设置为1,并存在变量里

ax=plt.gca()

#ax为两条坐标轴的实例

ax.xaxis.set_major_locator(x_major_locator)

#把x轴的主刻度设置为1的倍数

ax.set_xticklabels(labels=['2001-2002','2002-2003','2003-2004','2004-2005','2005-2006','2006-2007','2007-2008','2008-2009','2009-2010','2010-2011','2011-2012','2012-2013','2013-2014','2014-2015','2015-2016','2016-2017','2017-2018'],rotation=320)

plt.legend(labels = ['normalization1', 'normalization2'], loc = 'best',fontsize=20)

#第三个图表

plt.subplot(223)

plt.plot(year,reservoirDis,c='b',marker='^',linewidth=2)

plt.plot(year,reservoirArea,c='r',marker='^',linewidth=2)

#设置图表标题,并给坐标轴加上标签

plt.title(u"(c)3",fontsize=20)

plt.xlabel("Year", fontsize=16)

#设置刻度标记的大小

plt.tick_params(axis='both', labelsize=12)

x_major_locator=MultipleLocator(2)

#把x轴的刻度间隔设置为1,并存在变量里

ax=plt.gca()

#ax为两条坐标轴的实例

ax.xaxis.set_major_locator(x_major_locator)

#把x轴的主刻度设置为1的倍数

ax.set_xticklabels(labels=['2001-2002','2002-2003','2003-2004','2004-2005','2005-2006','2006-2007','2007-2008','2008-2009','2009-2010','2010-2011','2011-2012','2012-2013','2013-2014','2014-2015','2015-2016','2016-2017','2017-2018'],rotation=320)

plt.legend(labels = ['normalization1', 'normalization2'], loc = 'best',fontsize=20)

#第四个图表

plt.subplot(224)

plt.plot(year,cannelDis,c='b',marker='^',linewidth=2)

plt.plot(year,cannelArea,c='r',marker='^',linewidth=2)

#设置图表标题,并给坐标轴加上标签 h

plt.title(u"4",fontsize=20)

plt.xlabel("Year", fontsize=16)

#设置刻度标记的大小

plt.tick_params(axis='both', labelsize=12)

x_major_locator=MultipleLocator(2)

#把x轴的刻度间隔设置为1,并存在变量里

ax=plt.gca()

#ax为两条坐标轴的实例

ax.xaxis.set_major_locator(x_major_locator)

#把x轴的主刻度设置为1的倍数

ax.set_xticklabels(labels=['2001-2002','2002-2003','2003-2004','2004-2005','2005-2006','2006-2007','2007-2008','2008-2009','2009-2010','2010-2011','2011-2012','2012-2013','2013-2014','2014-2015','2015-2016','2016-2017','2017-2018'],rotation=320)

plt.legend(labels = ['normalization1', 'normalization2'], loc = 'best',fontsize=20)

plt.tight_layout()

#plt.savefig('centroid.jpg', format='jpg', dpi=1000)

plt.show()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容