Matlab绘制双纵轴

1.用到的命令是plotyy
clc;
clear;
x=0:0.1:2*pi;
y1=sin(x);
y1=y1';
y2=cos(x);
y2=y2';
y3=-cos(x);
y3=y3';
[AX,H1,H2] = plotyy(...
    x,y1,...
   x,[y2,y3],...
    'plot');
hold on;
set(get(gca,'xlabel'),'string','X-axis');
set(get(AX(1),'Ylabel'),'string','left Y-axis');
set(get(AX(2),'Ylabel'),'string','right Y-axis');
set(gca,'xTick',[0:1:7]); %设定X坐标范围
set(gcf,'Position',[100 100 260 220]);
set(AX(1),'ylim',[-1,2],'yTick',[-1:0.5:2]); %设定左侧Y坐标范围
set(AX(2),'ylim',[-1,1],'yTick',[-1:0.5:1]); %设定右侧Y坐标范围
h=legend('a','b','c');
set(h,'Box','off');
set(h,'fontsize',3,'fontweight','b','Location','NorthWest')
set(H2(1),'LineStyle','-','color','k','LineWidth',1);
set(H2(2),'LineStyle','-','color','k','LineWidth',1);


猜你喜欢

转载自blog.csdn.net/hguo11/article/details/53088688