代码:
figure(1)
yyaxis left
bar(num,duration,'EdgeColor',[0.75 0.75 0.75],'linewidth',1)
ylabel('Duration(month)')
ax=gca;
ax.XLim=[0 742];
ax.YLim=[1 50];
set(gca,'yTick',[1,10,20,30,40,50]);
set(gca,'YTickLabel',{'1','10','20','30','40','50'})
set(gca,'ycolor',[0.3 0.3 0.3]);%改左边坐标轴颜色
hold on
yyaxis right
plot(num,duration2,'color',[153 0 2]/255,'linewidth',1.5)
hold on
set(gca,'ycolor',[153 0 2]/255);%改右边坐标轴颜色
% pos=get(gcf,'position');
set(gcf,'position',pos)
set(gca,'xTick',[0,107,231,357,501,657,742]);
set(gca,'XTickLabel',{'1961','1970','1980','1990','2000','2010','2018'})
set(gca,'FontSize',18,'Fontname','Times New Roman')
ylabel('Duration(month)')
ax=gca;
ax.XLim=[0 742];
ax.YLim=[1 15];
set(gca,'yTick',[1,5,10,15]);
set(gca,'YTickLabel',{'1','5','10','15'})
legend('SPEI mon','SPEI movingAvg','orientation','horizontal')%图例
legend boxoff;
%set(gcf,'windowstyle','normal')
set(gca,'linewidth',1.5)
set(gcf,'position',pos)
print(gcf,'-r600','-dpng','G:***\**.png');
close