How to change the color of a plot with two y-axes on the same graph in Matlab
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
KALYAN ACHARJYA
on 27 Sep 2019
Edited: KALYAN ACHARJYA
on 27 Sep 2019
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 Comments
KALYAN ACHARJYA
on 27 Sep 2019
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');
More Answers (2)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!