改变颜色有两种方法:
第一种
在开头就设置
close all
fig = figure;
left_color = [0 0 1];
right_color = [0 1 0];
set(fig,'defaultAxesColorOrder',[left_color; right_color]);%然后绘图
yyaxis left %左侧
plot(1:5,5:-1:1,'LineStyle','-','color',[0,0,0.5],'LineWidth',2)
xlabel('x','FontName','Arial','FontSize',16)
ylabel('y1','FontName','Arial','FontSize',16)yyaxis right%右侧
plot(5:10,5:10,'LineStyle','-','color',[0,1,0],'LineWidth',2)
ylabel('y2','FontName','Arial','FontSize',16)
第二种
在对应坐标轴启动的时候分别设置
close all
figure;%绘图
yyaxis left %左侧
plot(1:5,5:-1:1,'LineStyle','-','color',[0,0,0.5],'LineWidth',2)
xlabel('x','FontName','Arial','FontSize',16)
ylabel('y1','FontName','Arial','FontSize',16)
set(gca,'ycolor',[0 0 1]);yyaxis right%右侧
plot(5:10,5:10,'LineStyle','-','color',[0,1,0],'LineWidth',2)
ylabel('y2','FontName','Arial','FontSize',16)
set(gca,'ycolor',[0 1 0]);