change appearence of 3rd plot in plotyy and plot legend

2 views (last 30 days)
I am trying to have 3 different plots show in the same graph. I have one plot associated with the left y-axis and 2 plots associated with the right y-axis. I am having a problem differentiating the 2 plots associated with the right axis. Can you help me get the right associated plots to show as '-.' in red and ':' in green? Here is my code:
samples = (1:100)';
theta_1 = 0 + (90)*rand(100,1);
r2v = 0 + (0.5)*rand(100,1);
r3v = 0 + (0.5)*rand(100,1);
% plot(samples, theta_1, '.r', samples, r2v, '.b', samples, r3v, '.g' );
[hAx,hLine1,hLine2] = plotyy(samples,theta_1, [samples',samples'], [r2v',r3v']);
hLine1.LineStyle = '-.';
hLine2.LineStyle = ':';

Answers (1)

Jacky Jo
Jacky Jo on 27 Oct 2015
Check the following. Also, check the range of theta_1 and (r2v or r3v). If you try to plot these three in a graph you can't see r2v and r3v that much; since it have range much lesser than theta_1. Therefore I did in separate plots.
samples = (1:100)';
theta_1 = 0 + (90)*rand(100,1);
r2v = 0 + (0.5)*rand(100,1);
r3v = 0 + (0.5)*rand(100,1);
plot(samples, theta_1,'.r'); % Check the Y scale of fig1 and fig 2
figure; hold on;
plot (samples, r2v, '.b');
plot (samples, r3v, '.g' );
[hAx,hLine1,hLine2] = plotyy(samples,theta_1, [samples',samples'], [r2v',r3v']);
  1 Comment
monkey_matlab on 27 Oct 2015
Edited: monkey_matlab on 27 Oct 2015
Hello, but since we are plotting r2v and r3v with reference to the right y-axis, show it not also be able to show up properly on the same figure? theta_1 is referenced to the left y-axis and should be independent of r2v and r3v?

Sign in to comment.


Find more on Two y-axis 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!