legend in 2d line plot
Show older comments
I'm plotting data in a for loop where I'm looping through two datasets so using plot...; hold on;plot...
I only want the legend for the first plot, but there doesn't seem to be a way of doing this. Any advice?
Failing this, is there a way of adding a graph onto a currently existing graph. So, that I could just plot the first with a legend and then plot the second on top of this without a legend?
The code I've written is shown below:
for i = 1:length(LakeName);
for ii = 1:length(CorrVariables)
fh{ii} = figure(ii);
plot(HiResDay,HiRes.(LakeName{i}).(CorrVariables{ii}),'linewidth',2,'color',cmap(i,:));hold on;
plot(LowResDay,LowRes.(LakeName{i}).(CorrVariables{ii}),'--k','linewidth',3);
hTitle = title ([CorrVariables{ii} ' 2011']);
hXLabel = xlabel('Time (Day of year)' );
hLegend = legend(LakeName{:});
end
end
This doesn't work as I expected; the legend shows the line for the first plot and then the second, then back to the first, so in the end I have the first legend entry in the designated color, then the second legend entry shown according to '--k'.
Accepted Answer
More Answers (0)
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!