matplotlib画图-时间序列折线图
今天做了⼀下毕设的图(关于结果⽐较的 时间序列图)
⾸先我说明 了半天的博客 没有到好的⽅法做x轴为datetime,很⿇烦 所以我打算做int32类型的,但发现没法转换 结果采⽤特殊⽅法解决的
matplotlib中subplot1.数据集查看
int64有个问题:就是在x轴的时候会出现0.5
2.将year转换为index
a = data.set_index(['YEAR'])
a.index
Int64Index([2011, 2012, 2013, 2014], dtype='int64', name='YEAR')
3. 转存数据
TAS = a.iloc[:,0]
QLD = a.iloc[:,1]
WA = a.iloc[:,2]
NATION = a.iloc[:,3]
VIC = a.iloc[:,4]
NSW = a.iloc[:,5]
SA = a.iloc[:,6]
TAS1 = a.iloc[:,7]
QLD1= a.iloc[:,8]
WA1 = a.iloc[:,9]
NATION1 = a.iloc[:,10]
VIC1 = a.iloc[:,11]
NSW1=a.iloc[:,12]
SA1=a.iloc[:,13]
index类型还是int64 如何解决呢?
3.plot
注意 :解决 设置xy轴的刻度 xticks 和yticks进⾏限制
plt.figure(1)
#plt.subplot(221)
plt.plot(TAS.index.values,TAS.values,'o-k')
plt.plot(QLD.index.values,QLD.values,'o-')
plt.plot(WA.index.values,WA.values,'o-y')
plt.plot(NATION.index.values,NATION.values,'o-c')
plt.plot(VIC.index.values,VIC.values,'o-r')
plt.plot(NSW.index.values,NSW.values,'o-g')
plt.plot(SA.index.values,SA.values,'o-m')
plt.axis([2011,2014,0.04,0.18])
#设置横纵坐标的刻度
#------标位置名称图例
<(2014,0.108,'TAS')
<(2014,0.09,'QLD')
<(2014,0.08,'WA')
plt.annotate('NATION',xytext=(2014,0.12),xy=(2014,0.076),arrowprops=dict(arrow)) plt.annotate('VIC',xytext=(2014,0.04),xy=(2014,0.075),arrowprops=dict(arrow)) (2014,0.07,'NSW')
<(2014,0.06,'SA')
plt.ylabel("RMSE")
plt.xlabel("(a) LSTM")
#
plt.figure(2)
#plt.subplot(222)
plt.plot(TAS1.index.values,TAS1.values,'o-k')
plt.plot(QLD1.index.values,QLD1.values,'o-')
plt.plot(WA1.index.values,WA1.values,'o-y')
plt.plot(NATION1.index.values,NATION1.values,'o-c')
plt.plot(VIC1.index.values,VIC1.values,'o-r')
plt.plot(NSW1.index.values,NSW1.values,'o-g')
plt.plot(SA1.index.values,SA1.values,'o-m')
plt.axis([2011,2014,0.04,0.18])
#设置横纵坐标的刻度
#------标位置名称图例
<(2011,0.11,'TAS')
<(2011,0.15,'QLD')
<(2011,0.102,'WA')
#plt.annotate('NATION',xytext=(2014,0.12),xy=(2014,0.126),arrowprops=dict(arrow)) #plt.a
nnotate('VIC',xytext=(2014,0.10),xy=(2014,0.15),arrowprops=dict(arrow)) (2011,0.12,'NATION')
<(2011,0.14,'VIC')
<(2011,0.09,'NSW')
<(2011,0.08,'SA')
plt.ylabel("RMSE")
plt.xlabel("(b) SE")
plt.show()
plt.savefig('example.jpg',format='jpg')

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。