How do I make matlab legends match the colour of the graphs?

Posted by Alex Gosselin on Stack Overflow See other posts from Stack Overflow or by Alex Gosselin
Published on 2010-05-10T18:29:09Z Indexed on 2010/05/10 18:34 UTC
Read the original article Hit count: 469

Filed under:
|

Here is the code I used:

x = linspace(0,2);
e = exp(1);
lin = e;
quad = e-e.*x.*x/2;
cub  = e-e.*x.*x/2;
quart = e-e.*x.*x/2+e.*x.*x.*x.*x/24;
act = e.^cos(x);
mplot = plot(x,act,x,lin,x,quad,x,cub,x,quart);
legend('actual','linear','quadratic','cubic','quartic')

This produces a legend matching the right colors to actual and linear, then after that it seems to skip over red on the graph, but not on the legend, i.e. the legend says quadratic should be red, but the graph shows it as green, the legend says cubic should be green, but the graph shows it as purple etc.

Any help is appreciated.

© Stack Overflow or respective owner

Related posts about matlab

Related posts about graphs