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

40 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 25 Ott 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{:})

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti


Release

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by