using plotyy for multiple plots

5 views (last 30 days)
Soroush
Soroush on 16 Jul 2015
Commented: Walter Roberson on 16 Jul 2015
I have four plots, to be plotted in the same figure. Two plots are for a y-axis on the right hand side and two for the left hand side. for each pair, the x values are different. For example:
% Two plots for y at right axis
x1 = 0:10;
x2 = 0:5;
y1 = rand(1,11);
y2 = rand(1,6);
% Two plots for y at left axis
x3 = 0:10;
x4 = 0:5;
y3 = rand(1,11);
y4 = rand(1,6);
How can I plot them in a same figure with plotyy or any other command?
Thanks, :)
Soroush

Answers (1)

Walter Roberson
Walter Roberson on 16 Jul 2015
ax = plotyy(x3, y3, x1, y1); %left then right
line(ax(1), x4, y4); %add another line to left axis
line(ax(2), x2, y2); %add another line to right axis
  2 Comments
Soroush
Soroush on 16 Jul 2015
Thank you very much for the response. However, I receive an error for using line command:
Error using line
Vectors must be the same lengths.
Walter Roberson
Walter Roberson on 16 Jul 2015
ax = plotyy(x3, y3, x1, y1); %left then right
line(x4, y4, 'Parent', ax(1)); %add another line to left axis
line(x2, y2, 'Parent', ax(2)); %add another line to right axis

Sign in to comment.

Categories

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!