How can I force legend not to overlap the graph?

128 ビュー (過去 30 日間)
GIorgi Tsutskiridze
GIorgi Tsutskiridze 2019 年 6 月 17 日
コメント済み: Olivia Plunkett 2020 年 11 月 7 日
I am trying to save figure from .fig to png format but the legend changes its place.
The .fig file that I am trying to save .png from is attached to the post. On my screen it looks like the following (produced using snipping tool on windows).
For forum.PNG
So, I want to save png exactly in the same form as it appears here on the screen. For this I click on File>Save As>Choose png format and save but it results in the following picture.png
for_forum.png
As you clearly see, legened is overlapped. Also the resolution of the picture is 768x576 which is almost quadratic. I want it to be more like a perpenndicular (wider as it is above produced using snipping tool)
Can anyone help me resolve this problem?

回答 (2 件)

Ruger28
Ruger28 2019 年 6 月 17 日
legend(legendNames,'Location','southeastoutside')
This will shift the legend outside of the graph. you can try
legend(legendNames,'Location','best') % or best outside
for a different view.
  2 件のコメント
GIorgi Tsutskiridze
GIorgi Tsutskiridze 2019 年 6 月 17 日
編集済み: GIorgi Tsutskiridze 2019 年 6 月 17 日
Unfortunately, I do not have the code. What I have is only .fig file. Is not it possible to do it using dialogbox?
Olivia Plunkett
Olivia Plunkett 2020 年 11 月 7 日
The default legend placement obscured part of my graph, but this fixed the problem. Thanks!

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


Abdulaziz Milhem
Abdulaziz Milhem 2020 年 4 月 17 日
you can use the following:
openfig('figurename.fig')
legend('Location','best');
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 4 月 17 日
It would be a bit more complicated than that. The original poster shows four or more axes, and legends are associated with axes (but are not children of axes). It would be necessary to find the legend object. Possibly
fig = openfig('figurename.fig');
legobjs = findall(fig, 'type', 'legend');
for K = 1 : length(legobjs) %loop in case there are several
legobjs(K).Location = 'best';
end
However in my brief test, "best" turned out to be right on top of a line, whereas northwest inside would have been fine in my test. So it might be necessary to tweak the "best"

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

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by