How do I add additional plots to either of the two y-axes when using the PLOTYY function?
13 views (last 30 days)
Show older comments
I am using the PLOTYY function to create a single plot with one x-axis and two y-axes. I am plotting a time-series vector on each of these y-axes using the following statement:
plotyy(x, y1, x, y2, 'plot');
I would like to know how to add additional plots to either of these two y-axes. For example, I may want 3 time-series plots for the first y-axis and 2 time-series plots for the second y-axis.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
You may plot multiple lines on both axes by either concatenating the data or using the HOLD function. For example:
% define the data
figure
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 1./exp(-0.05*x).*cos(x);
y3 = 200*cos(x);
y4 = 0.8*exp(-0.5*x).*sin(10*x);
y5 = 0.8*exp(-0.5*x).*cos(x);
% plotting the data on the two axes
[AX H1 H2] = plotyy(x, [y1; y2; y3], x, [y4; y5], 'plot');
Note that each of the time-series vectors y1 through y5 are row vectors. Their vertical concatenation allows us to plot all of them simultaneously.
Using the HOLD function:
figure
%plot data on both axes
[AX H1 H2] = plotyy(x, y1, x, y4, 'plot');
%hold both axes
hold(AX(1));
hold(AX(2));
%plot additional data to the axes
plot(AX(1),x,y2,'c');
plot(AX(1),x,y3,'r');
plot(AX(2),x,y5,'m');
0 Comments
More Answers (0)
See Also
Categories
Find more on Combine Multiple Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!