Matlab设置双y轴特性

前几天帮人搞一个图表, 搞了好久都没成功, 今天偶然来了灵感, 写写, 果然成功了, 赶紧分享下。

代码如下:

clc;
clear all;
close all;

x=2007:1:2012;
y1=[2757,3423, 3890,4985,6067.64,6772.4];
y2=[0.27, 0.3665,0.3256,0.3,0.3135,0.347];

 [AX,H1,H2] = plotyy(x,y1,x,y2);

 set(AX(:),'Ycolor','k')
set(get(AX(1),'Ylabel'),'string','现金股利总额(/亿元)','color','k','linewidth',1.0); 
set(get(AX(2),'Ylabel'),'string','占净利润比例(%)','color','k','linewidth',1.0); 
%set(AX,'Xlim',[0.5,26.5],'xTick',[1:1:5]);
set(AX,'Xlim',[2007,2012]);
xlabel('年份');
set(AX(1),'Ylim',[0,8000],'yTick',[0:1000:8000]);  % 可以自己设置范围, 坐标值
set(AX(2),'Ylim',[0,0.8],'YTick',[0:0.1:0.8]);
set(H1,'LineStyle','-','Marker','*','color','k','linewidth',1.0);
set(H2,'LineStyle','-','Marker','v','color','k','linewidth',1.0);
legend('现金股利总额(亿元)','占净利润比例');
 


示意图:

你可能感兴趣的:(Matlab设置双y轴特性)