Is there an equivalent to CLEGENDM for contour plots in MATLAB (R2013a)?

28 views (last 30 days)
How can I add a legend to my contour plot? Why is CLEGENDM only available as part of the Mapping Toolbox? This function would save lots of time when creating a legend for a contour plot, and having a similar feature in base MATLAB is something most users would like to see.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
There is no equivalent to CLENGENDM in base MATLAB. Here is an example that shows how you can add a legend to a contour plot:
clc
clear all
close all
x = -3:0.125:3;
y = -3:0.125:3;
[X,Y] = meshgrid(x,y);
Z = peaks(X,Y);
v = -2 : 1 : 2;
figure
contour(X,Y,Z,v);
leg = arrayfun(@num2str,v,'UniformOutput',false);
hc = get(gca,'children');
c = {leg};
legend(get(hc,'Children'),'String',c{:})

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2013a

Community Treasure Hunt

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

Start Hunting!