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

44 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 25 de Oct. de 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{:})

Más respuestas (0)

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Productos


Versión

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by