Hi EM,
I understand you are interested in modifying the legend in a contour plot to use straight lines instead of contour symbols.
Assuming you are using MATLAB R2014b or later, there are some possible workarounds that you can use for this. One way to create a legend containing the colors of the contours is to create invisible lines with the colors of the contour plots. You can either plot NaN values in the figure, which will not directly show up in the figure, or you can create a Line object and set its 'Visible' property to 'off'. The following example code shows how you can do both:
x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X)+cos(Y);
figure
hold on
contour(X,Y,Z,(-2:0.5:2),'Color','r');
hRed = plot(NaN, '-r');
contour(X,Y,Z*2,(-12:4:12)/3,'Color','b');
hBlue = plot(NaN, '-b');
legend([hRed hBlue], 'red', 'blue');
figure
line(X(1:2),Y(1:2),'Color','r','Visible','off');
line(X(1:2),Y(1:2),'Color','b','Visible','off');
legend('red','blue');
hold on
contour(X,Y,Z,(-2:0.5:2),'Color','r');
contour(X,Y,Z*2,(-12:4:12)/3,'Color','b');
hold off
I hope this information proves to be helpful.
Matt
Best Answer