Plot legend does not display any lines

조회 수: 25 (최근 30일)
DoubleD
DoubleD 2019년 10월 2일
댓글: Siphiwo Mzekandaba 2023년 10월 1일
Hi,
I am plotting a simple graph from a matrix, but when I code as below, the legend does not show any lines, but shows legend names only.
plot(kmat,v(:,1))
title('Convergence of Value Functions')
xlabel('k')
ylabel('v(k)')
hold on
plot(kmat,v(:,5))
plot(kmat,v(:,50))
plot(kmat,v(:,1000))
legend('iter=1','iter=5','iter=50','iter=1000')
hold off
"kmat" is N x 1 matrix for x-axis value, and "v" is N x N matrix where i want to plot values on y-axis.
However, as you can see from the plot below, the legend displays its names but doesn't display any corresponding line.
legend_problem.png
  댓글 수: 13
Star Strider
Star Strider 2020년 11월 17일
Paul Stansell —
I have no idea what the problem actually was. I updated the driver (using the ‘Auto-Detect and Install Radeon™ Graphics Drivers for Windows®’ app on the AMD Drivers and Support site) and after that, everything worked as it should, on both my desktop and laptop (both Ryzen+Radeon). There are several posts about this, and in every situation, upgrading the graphics driver solved the problem.
Matthew Fracalanza
Matthew Fracalanza 2021년 2월 22일
편집: Matthew Fracalanza 2021년 2월 22일
That worked, Star Strider. Thanks so much.

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

채택된 답변

darova
darova 2019년 10월 3일
Please see THIS solution for colorbar error

추가 답변 (4개)

Benoit Schiltz
Benoit Schiltz 2020년 9월 16일
Hi,
I have the same problem which was solved using
opengl software
But doing that makes the lines of the plot pixelized (this effect was not a problem before) displaying very little stairs between almost each step. Is there a way to fix this? I tried using
opengl hardware
Which solved the problem of the smoothness of the curves but then the legend colors and box disappeared.
Thanks
  댓글 수: 1
Antonio
Antonio 2023년 5월 12일
This works well! I am using R2022b.

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


Paul Stansell
Paul Stansell 2020년 11월 17일
편집: Paul Stansell 2020년 11월 17일
I have recently had a similar problem. opengl('save','software') did not work for me. Specifying ...'LineWidth',1) did. No idea why! (Actually, a line width >= 0.8 worked)
  댓글 수: 5
christos d
christos d 2021년 1월 13일
I can confirm that the issue is still there in matlab 2020b. But I can also confirm that using exactly the same laptop in other script it displays the dots of the legend the way it should. The script that I noticed it has the issue, happens to be a function file with nested function that provides results running it directly from the function file. I am not sure if it has to do with the matlab type of file or not, probably not.I do have an AMD processor by the way.
Siphiwo Mzekandaba
Siphiwo Mzekandaba 2023년 10월 1일
I am using R2021a, specifying ...'LineWidth', 1) worked for me.

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


Sergio Sanz
Sergio Sanz 2020년 4월 3일
I have the same problem and I've found that it only happens when lines are 0.5 width. If you change to 1 You can see both the edge of the legend and the lines of data inside the legend.
But I don't know what's the problem.
That's only a provisional solution.
  댓글 수: 2
parson fu
parson fu 2020년 5월 23일
I see the same problem too,but in another computer,it works fine.
PAVEL
PAVEL 2022년 9월 10일
It's a really solution, I just want to add it's neccessary to specify 'LineWidth' for each of plots for proper work.

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


Aisha Alshamrani
Aisha Alshamrani 2021년 3월 24일
I have the same problem , i try to use opengl but it didn’t work
  댓글 수: 1
Adam Danz
Adam Danz 2021년 3월 24일
편집: Adam Danz 2021년 3월 24일
See Paul's answer on this page or Star Strider's answer in another thread.

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

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by