Why am I unable to display more than two legend entries for the PLOTYY function in MATLAB 7.1(R14SP3)?

1 view (last 30 days)
I have more one data set per scale in the same PLOTYY graph. I would like to display the associated legends for each data set in the plot.
If I execute the following code:
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
plotyy([x,x],[y1 y1*2],x,y2)
I would like to display a legend for each data set in the plot.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This enhancement has been incorporated in Release 2008a (R2008a). For previous product releases, read below for any possible workarounds:
The PLOTYY function applies two axes, one overlaying the other with a transparent background. Each axes can have a legend. However, when applying the PLOTYY function in a vectorized format, for example,
plotyy([x,x],[y1 y1*2],x,y2)
the data for all of the lines on an axes is stored in one line object. Therefore, each legend cannot have more than one legend entry without generating the following warning:
Warning: Ignoring extra legend entries.
For example:
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[ax, h1, h2] = plotyy([x,x],[y1 y1*2],x,y2)
legend(ax(1), 'str1','str2');
legend(ax(2), 'str3');

More Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!