我有以下代码:
X = 0:pi/100:0.25*pi;
Y1 = sin(X);
Y2 = cos(X);
Y3 = tan(X);
fh = figure('toolbar','none','menubar','none','Units','characters');
Pan1 = uipanel(fh,'Units','normalized','Position',[0 0 0.5 1],'title',...
'Panel1');
Pan2 = uipanel(fh,'Units','normalized','Position',[0.5 0 0.5 1],'title',...
'Panel2');
haxes = axes('Parent',Pan2,'Units', 'normalized','Position',...
[0.125 0.1 0.75 0.75]);
hplot = plot(haxes,X,Y1,X,Y2,X,Y3);
xlabel(haxes,'Time (second)');
ylabel(haxes,'Amplitude (meter)');
title(haxes,'Trigonometric functions');
Ley = {'Sine function','Cosine function','Tangent function'}; %# legend's strings values
legend(haxes,Ley,'Location','SouthOutside');
[FileName,PathName,FilterIndex] = uiputfile('*.bmp;*.png;*.jpg;*.tif','Save as');
ftmp = figure('Menu','none','Toolbar','none','Units','normalized',...
'Position',[-1000 -1000 1 1]);
set(gcf,'PaperPositionMode','auto');
set(gcf,'InvertHardcopy','off');
new_axes = copyobj(haxes, ftmp);
legend(new_axes,Ley,'Location','SouthOutside','FontSize',8);
set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
fmtgraf = {'-dbmp','-dpng','-djpeg','-dtiff'};
fmt = fmtgraf{FilterIndex};
print(ftmp,fmt,FileName,'-r0');
delete(ftmp);
delete(fh);
从代码中可以看出,命令行
图例(new_axes,Ley,'位置','SouthOutside','FontSize',8);
在命令行之前运行
set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
正因为如此,图像看起来被它的低部分切割,如下所示(与属性/值“FontSize”的存在或不存在无关)
如果命令行
legend(new_axes,Ley,'Location','SouthOutside','FontSize',8);
在命令行之后运行
set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);
现在图像被其低部分切割,但在这种情况下,既看不到 xlabel 文本也看不到图例框(如下所示)
如果'FontSize',8
被压制,一切正常。如果我希望图例的尺寸更小,我该如何解决这个问题?