Histogram's legend is broken

조회 수: 7 (최근 30일)
Anantha Padmanabhan
Anantha Padmanabhan 2024년 10월 14일
댓글: DGM 2024년 10월 15일
The legend box where line style ought to come is broken and is showing blank instead. How do I make it work? I restarted matlab and tried to disable and re-enable legends using Insert > Legend in the menu strip above the histogram, but no good. Here is the image:-
legend broken image
Thanks in advance.
  댓글 수: 2
Sreeram
Sreeram 2024년 10월 14일
I am assuming that you are using "histogram" with DisplayStyle="stairs". However, I could not reproduce this issue in MATLAB R2024b:
histogram(randn(20,1), DisplayStyle="stairs")
legend
If you could share the reproduction steps and the MATLAB release, it will help the community to look into and guide you better.
Anantha Padmanabhan
Anantha Padmanabhan 2024년 10월 14일
Thanks for looking into Sreeram. I am using r2024a version and your assumption regarding stairs is correct. Apologies for missing them in the question itself.

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

채택된 답변

Sreeram
Sreeram 2024년 10월 14일
I was able to reproduce this issue in MATLAB R2024a and it appears like a bug to me. You may fix this by either upgrading to MATLAB R2024b or downgrading to MATLAB R2023b or before.
If it is not feasible, you may work around the issue in MATLAB R2024a itself based on these examples:
1. Change the “DisplayStyle” to “bar” momentarily:
h = histogram(randn(100,1),DisplayStyle="stairs");
legend
h.DisplayStyle = "bar";
pause(0.01) % The pause is necessary.
h.DisplayStyle = "stairs";
2. Use a hidden plot to create a custom legend:
h = histogram(randn(100,1),DisplayStyle="stairs");
hold on;
hidden = plot(NaN, "SeriesIndex", h.SeriesIndex);
legend(hidden)
hold off
I hope it helps!
  댓글 수: 4
Sreeram
Sreeram 2024년 10월 15일
Hi @DGM, I tried it but I see that the momantary displaying of the "bar" histogram is noticable when using "drawnow" instead of "pause(0.01)". Seems like "pause(0.01)" suits better in this case.
DGM
DGM 2024년 10월 15일
Hm. I guess that's a good point.
I'm running R2019b, so I couldn't really test the problem.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by