The legend box in plot has no colors

조회 수: 68 (최근 30일)
Arihant Anchalia
Arihant Anchalia 2020년 4월 29일
답변: Luca Schibik 2022년 10월 27일
The legend box in matlab has no colours.
This is the code:
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1,'DisplayName','cos(x)')
hold on
y2 = cos(2*x);
plot(x,y2,'DisplayName','cos(2x)')
hold off
legend

답변 (3개)

Star Strider
Star Strider 2020년 5월 2일
This is a known problem with recent AMD graphics drivers.
See for example: Lines in legend are missing
Updated drivers that solve this problem may by now be available.
.

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020년 5월 2일
Hey Arihant,
Although I'm unable to reproduce the error that you mention at my end, I have noticed a few instances where other users have reported the same issue. Here are the links to those discussion on the MATLAB Answers forum:
As a workaround, please perform a clean reinstall of MATLAB and update your graphics drivers to get your code to work as expected.
Hope this helps!

Luca Schibik
Luca Schibik 2022년 10월 27일
Hi, I have the same issue. I resolved it by imposing LineWidth. Once you have set it, you will have full legend! Try this little code in order to check
x=0:0.1:10;
y=sin(x);
z=sin(2*x);
figure(1)
plot(x,y,'LineWidth',2)
ylim([-2 2])
hold on
plot(x,z,'LineWidth',2)
grid on
legend ('sin(x)','sin(2x)')
Hope this help!

카테고리

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