Record mantlab to draw a double y-axis graph

For details, see:

Matlab draws a double vertical axis diagram - Dark Planet - CSDN Blog - Matlab dual axis

%绘制双Y轴图形
clc
clear
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);

figure;
[hAx, hLine1, hLine2] = plotyy(x,y1, x,y2);

title('Multiple Decay Rates');
xlabel('Time (\musec)');

ylabel(hAx(1), 'Slow Decay'); % left y-axis
ylabel(hAx(2), 'Fast Decay'); % right y-axis

Effect:

 

 

clc
clear
%matlab
x = linspace(0, 10);
y1 = sin(3*x);
y2 = sin(3*x) .* exp(0.5*x);

yyaxis left; % 激活左边的轴
plot(x,y1);

Effect:

 

title('Title');
xlabel('X-axis');
ylabel('left Y-axis'); % 给左y轴添加轴标签

yyaxis right; % 激活右边的轴
plot(x,y2);
ylim([-150,150]); % 设置右y轴的界限
ylabel('right Y-axis'); % 给右y轴添加轴标签

Effect:

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_51229250/article/details/122942098