matlab调整legend方框大小

matlab调整legend方框大小,第1张

% 这里要画一个2*2共4幅子图。先将第1个子图的位置调整。

h = subplot( 2, 2, 1)% 先让MATLAB默 认绘制第1幅子图,h是子图1的句柄

po = get( h, 'Position' ) % get命令从句柄h中获取'Position'的内容,返回一个含4个元素的一维数组放到po中。这4个元 素分别是子图1的left, bottom, width, height。

subplot( 'Position', [po(1)+0.03, po(2)-0.03, po(3), po(4)]) 子图1的新位置可以这样调整

%----------------------------------

hold on

axis([0 13 -3 2])

set( gca, 'XTick', [1:12] ) gca表示当前对象句柄,set命令分别对当前对象(即子图1)设置坐标轴XTick和YTick属性。这 两个属性分别表示了坐标轴的实际绘值范围。

set( gca, 'YTick', [-3:1:2] )

title( 'The North Hemisphere' )

plot( 1:12, bc, '-r.', 'MarkerSize', 10 ) 子图1中第1条曲线用实线绘,带有圆点,红色。MarkerSize属性设 置圆点的大小是10。这样画出来的就是实心圆了。

plot( 1:12, nit, '-b.', 'MarkerSize', 10 )

plot( 1:12, sul, '-g.', 'MarkerSize', 10 )

plot( 1:12, poa, '-m.', 'MarkerSize', 10 )

plot( 1:12, soa, '-k.', 'MarkerSize', 10 )

%zeroArr = zeros( 14 )

%plot( 0:13, zeroArr, '--k' )

xlabel( 'Month' )

ylabel( 'Radiative Effect (Wm^-^2)' ) 单位里有上标,^表示后续一个字符为上标。

下述代码绘子图2、3、4,雷同。

%--------------------------------------------------------------------------

% NH Radiative Forcing Fut-Mod 子图2

fid_bc=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_NH\bc.dat','r')

bc = fscanf( fid_bc, '%f', [1,12])

fclose( fid_bc )

fid_nit=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_NH\nit.dat','r')

nit = fscanf( fid_nit, '%f', [1,12])

fclose( fid_nit )

fid_sul=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_NH\sul.dat','r')

sul = fscanf( fid_sul, '%f', [1,12])

fclose( fid_sul )

fid_poa=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_NH\poa.dat','r')

poa = fscanf( fid_poa, '%f', [1,12])

fclose( fid_poa )

fid_soa=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_NH\soa.dat','r')

soa = fscanf( fid_soa, '%f', [1,12])

fclose( fid_soa )

%----------------------------------

h = subplot( 2, 2, 3, 'replace' )

po = get( h, 'Position' )

subplot( 2, 2, 3, 'replace' )

subplot( 'Position', [po(1)+0.03, po(2)+0.03, po(3), po(4)])

%----------------------------------

box on

hold on

axis([0 13 -3 2])

set( gca, 'XTick', [1:12] )

set( gca, 'YTick', [-3:1:2] )

%title( 'NH Fut-Mod' )

plot( 1:12, bc, '-r.', 'MarkerSize', 10 )

plot( 1:12, nit, '-b.', 'MarkerSize', 10 )

plot( 1:12, sul, '-g.', 'MarkerSize', 10 )

plot( 1:12, poa, '-m.', 'MarkerSize', 10 )

plot( 1:12, soa, '-k.', 'MarkerSize', 10 )

%zeroArr = zeros( 14 )

%plot( 0:13, zeroArr, '--k' )

xlabel( 'Month' )

ylabel( 'Radiative Forcing (Wm^-^2)' )

%--------------------------------------------------------------------------

% SH Radiative Effect Mod-Noall 子图3

fid_bc=fopen('D:\_CurrentPaper\RadiativeForcing\ModNoall_SH\bc.dat','r')

bc = fscanf( fid_bc, '%f', [1,12])

fclose( fid_bc )

fid_nit=fopen('D:\_CurrentPaper\RadiativeForcing\ModNoall_SH\nit.dat','r')

nit = fscanf( fid_nit, '%f', [1,12])

fclose( fid_nit )

fid_sul=fopen('D:\_CurrentPaper\RadiativeForcing\ModNoall_SH\sul.dat','r')

sul = fscanf( fid_sul, '%f', [1,12])

fclose( fid_sul )

fid_poa=fopen('D:\_CurrentPaper\RadiativeForcing\ModNoall_SH\poa.dat','r')

poa = fscanf( fid_poa, '%f', [1,12])

fclose( fid_poa )

fid_soa=fopen('D:\_CurrentPaper\RadiativeForcing\ModNoall_SH\soa.dat','r')

soa = fscanf( fid_soa, '%f', [1,12])

fclose( fid_soa )

%----------------------------------

h = subplot( 2, 2, 2, 'replace' )

po = get( h, 'Position' )

subplot( 2, 2, 2, 'replace' )

subplot( 'Position', [po(1)-0.03, po(2)-0.03, po(3), po(4)])

%----------------------------------

box on

hold on

axis([0 13 -1.2 0.8])

set( gca, 'XTick', [1:12] )

set( gca, 'YTick', [-1.2:0.4:0.8] )

title( 'The South Hemisphere' )

plot( 1:12, bc, '-r.', 'MarkerSize', 10 )

plot( 1:12, nit, '-b.', 'MarkerSize', 10 )

plot( 1:12, sul, '-g.', 'MarkerSize', 10 )

plot( 1:12, poa, '-m.', 'MarkerSize', 10 )

plot( 1:12, soa, '-k.', 'MarkerSize', 10 )

%zeroArr = zeros( 14 )

%plot( 0:13, zeroArr, '--k' )

xlabel( 'Month' )

%ylabel( 'Radiative Effect (Wm^-^2)' )

%--------------------------------------------------------------------------

% SH Radiative Forcing Fut-Mod 子图4

fid_bc=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_SH\bc.dat','r')

bc = fscanf( fid_bc, '%f', [1,12])

fclose( fid_bc )

fid_nit=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_SH\nit.dat','r')

nit = fscanf( fid_nit, '%f', [1,12])

fclose( fid_nit )

fid_sul=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_SH\sul.dat','r')

sul = fscanf( fid_sul, '%f', [1,12])

fclose( fid_sul )

fid_poa=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_SH\poa.dat','r')

poa = fscanf( fid_poa, '%f', [1,12])

fclose( fid_poa )

fid_soa=fopen('D:\_CurrentPaper\RadiativeForcing\FutMod_SH\soa.dat','r')

soa = fscanf( fid_soa, '%f', [1,12])

fclose( fid_soa )

%----------------------------------

h = subplot( 2, 2, 4, 'replace' )

po = get( h, 'Position' )

subplot( 2, 2, 4, 'replace' )

subplot( 'Position', [po(1)-0.03, po(2)+0.03, po(3), po(4)])

%----------------------------------

box on

hold on

axis([0 13 -1.2 0.8])

set( gca, 'XTick', [1:12] )

set( gca, 'YTick', [-1.2:0.4:0.8] )

%title( 'SH Fut-Mod' )

plot( 1:12, bc, '-r.', 'MarkerSize', 10 )

plot( 1:12, nit, '-b.', 'MarkerSize', 10 )

plot( 1:12, sul, '-g.', 'MarkerSize', 10 )

plot( 1:12, poa, '-m.', 'MarkerSize', 10 )

plot( 1:12, soa, '-k.', 'MarkerSize', 10 )

%zeroArr = zeros( 14 )

%plot( 0:13, zeroArr, '--k' )

xlabel( 'Month' )

%ylabel( 'Radiative Forcing (Wm^-^2)' )

我将legend放在了子图4上。

gca=legend( 'BC', 'Nitrate', 'Sulfate', 'POA', 'SOA', 4 ) 4表示把legend放在子图的右下角,还有几个数字的含义是:

0 = Automatic "best" placement (least conflict with data)

1 = Upper right-hand corner (default)

2 = Upper left-hand corner

3 = Lower left-hand corner

4 = Lower right-hand corner

-1 = To the right of the plot

po=get( gca, 'Position' )发现这样放置后legend要挡住图,因此需要再微调一下。获得legend的'Position'值。

set( gca, 'FontSize', 8, 'Position', [po(1)-0.01, po(2)+0.01, po(3), po(4)] )重新设置legend的位置,同时设置legend里面的字体为8号。

legend('boxoff') 不画legend的外框。

强调的是上述调整legend的值要不断地试。因为legend相对子图的位置还要随画图窗口大小变 化而变化。如果你看不懂这句,试试就知道了。

我一般是将MATLAB画出的图打印成PDF,再用Acrobat打开截屏,贴到WORD中,这样图 像质量似乎比较好。谁还有更好的将MATLAB图转贴到WORD的方法,欢迎赐教。

鼠标右键设置。

右击legend(你所谓的方框),选择update刷新。或者删了,右击图片框,选择legend图标说明,重新创建一个legend。通过菜单命令也可实现。

Origin是由OriginLab公司开发的一个科学绘图、数据分析软件,支持在MicrosoftWindows下运行。Origin支持各种各样的2D/3D图形。

<!DOCTYPE html>

<html>

<body>

<form>

<fieldset>

<legend>在边框上的字</legend>

input:<input type="text" />

</fieldset>

</form>

<fieldset>

<legend>在边框上的字</legend>

input:<input type="text" />

</fieldset>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11340659.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存