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

44 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

产品


版本

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by