using plotyy for multiple plots

8 次查看(过去 30 天)
Soroush
Soroush 2015-7-16
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

回答(1 个)

Walter Roberson
Walter Roberson 2015-7-16
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 个评论
Soroush
Soroush 2015-7-16
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 2015-7-16
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by