2015-02-06 50 views
2

不同我有一个MATLAB脚本像这样:在R2014b Matlab的等高线图图例从以前的版本

x = linspace(-2*pi,2*pi); 
y = linspace(0,4*pi); 
[X,Y] = meshgrid(x,y); 
Z = sin(X)+cos(Y); 
Z1 = cos(.5*X) + sin(2*Y); 

figure 
[c h] = contour(X,Y,Z, '-r') 
hold on 
[c1 h2] = contour(X,Y,Z1, '-b') 
legend('test1', 'test2') 

我有同积2个等高线图,一个以红色显示,其他的以蓝色显示。问题在于图例不会以红色和蓝色显示。在老版本的matlab中,这工作得很好,但是你应该如何在R2014b中定义图例,以便它在'测试1'旁边具有红色轮廓并且在'测试2'旁边具有蓝色轮廓?

其他人在mathcentral上有一个非常类似的问题,但没有得到回答:http://www.mathworks.com/matlabcentral/answers/164210-how-does-the-contour-plot-with-r2014b-work

谢谢!

+0

有你看着['clegendm'](http://fr.mathworks.com/help/map/ref/ clegendm.html)? – Ratbert 2015-02-06 20:43:42

回答

1

根据文档,在R2014b“颜色条和图例具有新属性并且不支持某些轴属性”。由于contour返回的句柄现在是Contour对象,因此您可以做的事情很少。

不过,让你有这样的非常丑陋的黑客所期望的行为:

x = linspace(-2*pi,2*pi); 
y = linspace(0,4*pi); 
[X,Y] = meshgrid(x,y); 
Z = sin(X)+cos(Y); 
Z1 = cos(.5*X) + sin(2*Y); 

figure 
hold on 

[~, h1] = contour(X,Y,Z, '-r'); 
h1_ = plot(NaN, '-r'); 
[~, h2] = contour(X,Y,Z1, '-b'); 
h2_ = plot(NaN, '-b'); 

L = legend([h1_ h2_], 'test 1', 'test 2');