I'm plotting graphs of the same type in multiple subplots, with some subplots left blank. I'd like to use the blank spots to plot a legend. I could of course move the location of the legend but that's really tedious. The seemingly obvious, clean way to do this is as in the following code. In the sixth plot region, I plot my lines, create the legend, set autoupdate to off, then set the linestyles to 'none'. Trouble is: when I set the linestyles to none, the legend autoupdates and sets the legend lines to none as well. So what I need to do is break the link between the actual lines and the legend lines.
close all;for ii=1:2:9; subplot(3,3,ii); clear h; hold on; h(1) = plot(1:10); h(2) = plot(10:-1:1); if ii==5; subplot(3,3,6); hold on; h(1) = plot(1:10); h(2) = plot(10:-1:1); legend('up','down','AutoUpdate','off'); for ii=1:numel(h); h(ii).LineStyle='none'; end; end;end;
A hideous kludge is the following: close all;
for ii=1:2:9; subplot(3,3,ii); clear h; hold on; h(1) = plot(1:10); h(2) = plot(10:-1:1); if ii==5; subplot(3,3,6); hold on; h(1) = plot(11:20); h(2) = plot(20:30); legend('up','down','AutoUpdate','off'); set(gca,'YLim',[1,10]); end;end
But this is unsatisfactory in so many ways that I won't bother to enumerate them. So the question is, is there a clean way to do what I want to do, just by breaking the link between actual plot lines and legend lines, and not resorting to a hideous kludge?
Best Answer