Legend function does not work in R2019b

7 ビュー (過去 30 日間)
Hangjun He
Hangjun He 2019 年 10 月 12 日
編集済み: Star Strider 2020 年 10 月 2 日
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.

採用された回答

Star Strider
Star Strider 2019 年 10 月 12 日
編集済み: Star Strider 2020 年 10 月 2 日
It was pointed out recently in another Question with a problem similar to yours that:
is likely the appropriate solution.
EDIT — (1 Sep 2020 at 12:22)
This turned out to be a problem with certain AMD graphics drivers. The current versions (fixed a few months ago) correct the problem that caused this. Updating the AMD graphics driver solves it.
EDIT — (2 Oct 2020 at 19:33)
See this Comment for further details.
  2 件のコメント
Hangjun He
Hangjun He 2019 年 10 月 12 日
Thank you! It works. I use the command
opengl('save','software')
and now I get my desired result. Thank you for your help!
Star Strider
Star Strider 2019 年 10 月 12 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 10 月 12 日
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.
  2 件のコメント
Hangjun He
Hangjun He 2019 年 10 月 12 日
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.
RANJAN HALDER
RANJAN HALDER 2020 年 9 月 1 日
Thank You sir, opengl command didn't work for me by clearing all (excecuting clear all command), legend function is perfectly working for me.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by