필터 지우기
필터 지우기

Disappearing Legend: Saving a figure with a legend as a .fig file

조회 수: 2 (최근 30일)
Laura
Laura 2016년 9월 22일
편집: Laura 2016년 9월 22일
I am trying to save a figure with a legend positioned manually outside of the plot as a .fig file. When I generate the figure the legend is positioned exactly as I want it. I then save the file using the figure GUI, but when I reopen the saved figure the legend has "disappeared".
I'm fairly certain that this has something to do with the parent/child relationship between figures, axes and legends, but I'm a beginner in understanding the structure of the these objects in Matlab.
I am including a minimal example of what I am trying to do. I am generating the figure and legend in a loop because this is a necessary part of my "real" code. Any help or insight in where to look for an answer to this coding question would be appreciated.
%Problem Code
clear all;
fig1 = figure;
set(fig1,'units','centimeters','Position',[0 0 28 15]);
h_axes_1=axes('parent',fig1,'units','centimeters','Position',[3 3 13 9]);
hold on
for i = 1:1:5
plot(h_axes_1,[1:10],2*i*[1:10]);
Legendinfo{i} = ['i =' num2str(i)];
end
leg1 = legend(Legendinfo,'Units','centimeters','parent',fig1,'Position',[17 6 6 6]);
hold off
If I change the line of code that constructs the legend to
legend(Legendinfo,'Units','centimeters','parent',fig1,'Location','northeastoutside');
opening the saved file produces the same figure as the original file. That is, the issue of the disappearing legend is resolved.
While this is a "work around" I would much prefer being able to specify the exact location and size of my legend.
I am using release 2015b. This problem occurs whether I select the drop down "save" option from the file menu in the figure window or I use the "savefig" command in the command window.
Thanks.
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 9월 22일
Which MATLAB release are you using?
And please show your command to save the plot.
Laura
Laura 2016년 9월 22일
I am using the 2015b release. Currently I am just using the save option from the drop down file menu in the automatically generated matlab figure window.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by