MATLAB Answers

0

Legend function does not work in R2019b

Asked by Hangjun He on 12 Oct 2019
Latest activity Commented on by Star Strider
on 12 Oct 2019
The following lines of code is just a simple use of legend function.
x = linspace(0,2*pi,360);
y = sin(x);
plot(x,y);
legend('sin(x)');
But the result I get in my computer is incomplete: the legend dose not show the line of the curve.
sinx.png
I run the code in mac and it doesn't have this issue. My system is windows 10 and the version of matlab is R2019b. I don't know what causes this problem and hope someone can help me figure it out.

  0 Comments

Sign in to comment.

2 Answers

Answer by Star Strider
on 12 Oct 2019
 Accepted Answer

It was pointed out recently in another Question with a problem similar to yours that:
is likely the appropriate solution.

  2 Comments

Thank you! It works. I use the command
opengl('save','software')
and now I get my desired result. Thank you for your help!
As always, my pleasure!

Sign in to comment.


Answer by Sulaymon Eshkabilov on 12 Oct 2019

Hi,
Your code is running ok in Win 10 and MATLAB 2019b. You should close all figure windows, run clear all command or/and if possible restart your MATLAB. Then you should get the anticipated outcome from your code.
Just an additional step to test your MATLAB is to run this slightly edited code of yours:
x = linspace(0,2*pi,360);
y = sin(x);
plot(x,y, 'b-o');
legend('sin(x)');
Good luck.

  1 Comment

Hi,
Things didn't go smooth after I restart my MATLAB. But I solved this problem by this command
opengl('save','software')
Thank you anyway.

Sign in to comment.