一、方法一yyaxis函数
x = linspace(0,pi);
y1 = cos(x);
yyaxis left; % 激活左边的轴
plot(x,y1)
xlabel('X-axis');
ylabel('left Y-axis'); % 给左y轴添加轴标签
hold on
yyaxis right; % 激活右边的轴
y2 = cos(2*x);
plot(x,y2)
ylim([-1,1]); % 设置右y轴的界限
ylabel('right Y-axis'); % 给右y轴添加轴标签
二、更改坐标轴颜色
x = linspace(0,pi);
y1 = cos(x);
yyaxis left; % 激活左边的轴
plot(x,y1,'r')
xlabel('X-axis');
ylabel('left Y-axis'); % 给左y轴添加轴标签
ax = gca;
ax.YColor = 'r';
hold on
yyaxis right; % 激活右边的轴
y2 = cos(2*x);
plot(x,y2,'b')
ylim([-1,1]); % 设置右y轴的界限
ylabel('right Y-axis'); % 给右y轴添加轴标签
ax = gca;
ax.YColor = 'b';
三、方法二plotyy函数
x = linspace(0,pi);
y1 = cos(x);
y2 = cos(2*x);
[AX,H1,H2] =plotyy(x,y1, x,y2); % 绘制双轴图
HH1=get(AX(1),'Ylabel');
set(HH1,'String','Left Y-axis');
HH2=get(AX(2),'Ylabel');
set(HH2,'String','Right Y-axis');
四、更改坐标轴颜色文章来源:https://www.toymoban.com/news/detail-816610.html
x = linspace(0,pi);
y1 = cos(x);
y2 = cos(2*x);
[AX,H1,H2] =plotyy(x,y1, x,y2); % 绘制双轴图
HH1=get(AX(1),'Ylabel');
set(HH1,'String','Left Y-axis');
HH2=get(AX(2),'Ylabel');
set(HH2,'String','Right Y-axis');
xlabel('X');
set(AX(1),'XColor','k','YColor','b');
set(AX(2),'XColor','k','YColor','r');
set(H1,'color','b');
set(H2,'color','r');
set(HH1,'color','b');
set(HH2,'color','r');
文章来源地址https://www.toymoban.com/news/detail-816610.html
到了这里,关于Matlab绘制双纵轴图(yyaxis函数)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!