Wrong coloring of legend in semilogx plot

조회 수: 3 (최근 30일)
Nora
Nora 2014년 10월 30일
댓글: Nora 2014년 11월 10일
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
Chad Greene
Chad Greene 2014년 10월 30일
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 2014년 11월 10일
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...

댓글을 달려면 로그인하십시오.

채택된 답변

Matt Tearle
Matt Tearle 2014년 10월 30일
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
Nora
Nora 2014년 11월 10일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by