Wrong coloring of legend in semilogx plot

3 views (last 30 days)
I realized in both 2013a and 2013b that there seems to be a bug in the coloring in the semilogx function. Colors displayed in the legend are not even present in the plot itself and sometimes the order seems to be wrong. In any case it's not possible to say which color refers to which data. I tried solving this problem for some days now and I'm pretty desperate about it. It's the same result whether I call the function from a .m-file or directly from the command window. Any work around? That's the code I use
figure(3)
semilogx(f20,real(var20(:,8)), f40,real(var40(:,8)), f60, real(var60(:,8)),f80, real(var80(:,8)), f100, real(var100(:,8)))
legend('20','40','60', '80', '100')
The attached picture shows the disaster.
Thanks for your help!
  2 Comments
Chad Greene
Chad Greene on 30 Oct 2014
Can you give us your f20, etc data, or make some up?
Does the same problem happen if you use plot instead of semilogx?
Nora
Nora on 10 Nov 2014
Hi Chad,
looking into the data just now, when I wanted to answer your question, I probably found the solution. My f20 etc. data are a 48x18 matrix similar as the var-data. By not selecting a defined column the problem evolved. When I write f20(:,8) instead it seems to work. Thanks for leading me to the solution :) Sometimes one really makes dumb mistakes...

Sign in to comment.

Accepted Answer

Matt Tearle
Matt Tearle on 30 Oct 2014
I just tried an example in R2013b and it worked fine, but then I messed with it a bit and happened to get something very similar to what you're seeing. So try looking at the dimensions of your x variables, f60 in particular.
whos f*
When I used a matrix for one of the x variables, it got messed up. Perhaps f60 is a matrix instead of a vector?
If that's not the issue, is there any way you can share your variables with us? (Or, at very least, size/type/etc)
  1 Comment
Nora
Nora on 10 Nov 2014
Hi Matt,
I just realized when I looked into the data that this in fact was the case. What a stupid mistake of mine! Thanks for your valuable help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!