Can not make Legend border visible

With the code below. This the example code from https://www.mathworks.com/help/matlab/ref/legend.html
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)
hold on
y2 = cos(2*x);
plot(x,y2)
legend('cos(x)','cos(2x)')
I got
The legend looks like this, which I can not understand.
If you check the last question I raised. All my figures have some problems with the legend. I do not know why. It seems that I need to change some settings of the matlab. The 2019b and 2020a both have this legend problem.
It looks like a very basic question. But it really annoys me for some time.
Any help, many thanks!

1 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 8 月 22 日
I have used earlier one, no issue? Which version you are using?

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

 採用された回答

Star Strider
Star Strider 2020 年 8 月 22 日

1 投票

This is a problem with certain AMD graphics drivers.
First, see if there is an update for the AMD driver. If so, let the AMD software update it for you.
In the interim, use:
opengl('software')
and if you want to save that for future sessions:
opengl('save','software')
However, it would be best to update the driver before you use the 'save' option. In the latest AMD driver versions, this is no longer a problem.

4 件のコメント

qaqcvc
qaqcvc 2020 年 8 月 23 日
Thanks!You saved my life
That's the problem of my AMD graphics driver
Star Strider
Star Strider 2020 年 8 月 23 日
As always, my pleasure!
The newest driver versions do not have that problem (or any problems that I have been able to discover).
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 8 月 23 日
Great Sir +1
Star Strider
Star Strider 2020 年 8 月 23 日
Kalyan — Thank you!

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

その他の回答 (1 件)

the cyclist
the cyclist 2020 年 8 月 22 日

0 投票

There is a box around the legend by default, and I cannot remember that ever not being the case.
Does this happen from a freshly started instance of MATLAB, having run no other code first?
Immediately after starting MATLAB, I would try each of the following, to see if any of them mention the legend:
  • get(0)
  • get(gcf)
  • type startup.m

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2019b

質問済み:

2020 年 8 月 22 日

コメント済み:

2020 年 8 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by