How can I get a legend that identifies ALL series shown on a group of plots?
1 view (last 30 days)
Show older comments
I have 9 subplots on one figure. 7 of those 9 subplots, including the last subplot, only have 3 data series associated with the plots. However, the other 2 have 4 data series. How do I get the legend to retain the information about ALL of the series shown in the figure? See attached image. Notice that plots 5 and 6 have observed data on them, but the others (including the last one) does not. I need to the legend to reflect the observed data.
1 Comment
Matthew
on 7 Oct 2015
I believe the legend is associated with each individual axis rather than the figure, so there's probably no built in way to do this.
However, you could try making a hidden axis on the figure that contains a dummy series for each series in the figure. You could then create a legend for that hidden axis, and force the legend to be visible, even though its parent axis is hidden. . .
Accepted Answer
Kelly Kearney
on 7 Oct 2015
To do this, save the handles of the lines you want labeled and pass these to the legend command. They don't have to all share a parent figure.
ax(1) = subplot(2,2,1);
h1 = plot(rand(10,3));
ax(2) = subplot(2,2,2);
h2 = plot(rand(10,2));
ax(3) = subplot(2,2,3);
h3 = plot(rand(10,2));
set([h1;h2;h3], {'color'}, {'r';'g';'b';'c';'m';'y';'k'});
legend(ax(3), [h1;h2;h3], '1','2','3','4','5','6','7');
0 Comments
More Answers (0)
See Also
Categories
Find more on Legend 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!