How to change the color of a plot with two y-axes on the same graph in Matlab

1 view (last 30 days)
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')

Accepted Answer

KALYAN ACHARJYA
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
Fuad Nammas
Fuad Nammas on 27 Sep 2019
thanks alot dear brother..
but would you pease help me to make the axis "black'
while the curves one is "solid black"
and the other is "dashe black"
i will be greatful for you
KALYAN ACHARJYA
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');

Sign in to comment.

More Answers (2)

Fuad Nammas
Fuad Nammas on 27 Sep 2019
for the fist part of my question i used your codes but it changes the axis color and the curves color it dont work

Fuad Nammas
Fuad Nammas on 27 Sep 2019
Edited: Fuad Nammas on 27 Sep 2019
thanks alot dear brother..
but would you please help me to make
1- the axis "black'
2 while the curves one is "solid black"
3-and the other is "dashe black"
i will be greatful for you

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!