Legend error (does not display 'line' in legend box)

If I simply plot using the below code
x=0:0.1:10;
>> figure; plot(x,sin(x))
>> legend('on')
>> hold on
>> scatter(x, cos(x))
The figure looks like the below figure. The legend shows no 'line' for the first graph. It shows only circle.
How can I fix this problem?
untitled2.png

 Accepted Answer

Using:
opengl('save','software')
seems to be a solution for that problem.
See: Use Software OpenGL for Future Sessions and related topics for details.

5 Comments

Thanks for the reply.
However, why it happens? Matlab seems like they do not recommend this option.
Is it because of my graphic card? I am two PC. This problem occured on only one PC, which uses intergal graphic card (AMD Ryzen 2400G), but not for the other one (Intel 7700K with Nvidia VGA).
My pleasure.
I have no idea why it occurs. I have two computers that I use for MATLAB, both have Ryzen chips, one has an nVidia GPU and the other has an AMD GPU, and only the AMD card has this problem. Even updating the driver (just now) did not solve the problem.
To add to Star's answer, if you change the line width of the legend box to some value greater than 0.6, the box will appear, even with opengl hardware.
leg = legend(__);
leg.LineWidth= .601;
% or
legend(__,'LineWidth',0.601)
The actual solution is to upgrade to the latest AMD video card driver.
That option was not available when I wrote this, and is now.
EDIT — (2 Oct 2020 at 19:32)
See this Comment for further details.
My Windows 10 system indicates that my currently installed Radeon 540x Series is the best driver for the machine. I didn't have this problem on my 8-year old laptop. 😕
Your solution to use opengl software is a good one but it introduces other problems like jagged edges for some lines. The need to widen line widths is annoyoing but worth mentioning so others are aware of that workaround.

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!