Disappearing Legend: Saving a figure with a legend as a .fig file
2 ビュー (過去 30 日間)
古いコメントを表示
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
2016 年 9 月 22 日
Which MATLAB release are you using?
And please show your command to save the plot.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!