How to change the color of a plot with two y-axes on the same graph in Matlab
1 次查看(过去 30 天)
显示 更早的评论
dear all
for the following program
how i can change the color of each plot
x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure
plotyy(x,y1,x,y2)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay')
ylabel(hAx(2),'Fast Decay')
0 个评论
采纳的回答
KALYAN ACHARJYA
2019-9-27
编辑:KALYAN ACHARJYA
2019-9-27
x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure
plotyy(x,y1,x,y2)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
set(hAx(1),'ycolor','r'); % Change the color accordingly
set(hAx(2),'ycolor','c'); % Change the color accordingly
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay') ;
ylabel(hAx(2),'Fast Decay') ;
Or
x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure
plotyy(x,y1,x,y2)
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
set(hAx,{'ycolor'},{'r';'c'});
%..........x or y axex color, if x, use xcolor and change the colors accordingly
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay')
ylabel(hAx(2),'Fast Decay')
4 个评论
KALYAN ACHARJYA
2019-9-27
This way?
x = 0:0.01:20;
y1 = sin(x);
y2 = x;
figure % new figure
yyaxis left
plot(x,y1,'c');
yyaxis right;
plot(x,y2,'b');
更多回答(2 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!