Why does the legend of a contour plot in MATLAB 7.0 (R14) not look the way it did in MATLAB 6.5 (R13)?

1 view (last 30 days)
If you run the code below in MATLAB 6.5 (R13) and again in MATLAB 7.0 (R14), you will see the legends in those two plots are different.
Under MATLAB 6.5, each label in 'legend' is associated with a different fill color in the contour plot. Under MATLAB 7.0, only one label is shown, and the sample face color includes all the colors in the plot.
[C,h] = contourf(peaks(20),10);
legend('A', 'B', 'C')
When I try to execute this code, I receive the following error:
Warning: Ignoring extra legend entries.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
The way that plot legends are created in MATLAB 7.0 (R14) is different from how they were created in MATLAB 6.5 (R13).
To work around this issue, include 'v6' in the CONTOURF command. This causes the legend to be the same as it was in MATLAB 6.5.
[C,h] = contourf('v6',peaks(20),10);
legend('A', 'B', 'C')
See "Plot Objects and Backward Compatibility" in the Handle Graphics documentation for more information.

More Answers (0)

Categories

Find more on Contour 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!