Matlab: legend、axis坐标设置、colorbar、导出图片格式等问题的总结

1.legend

1).如何将图例设置在图片的任意位置?如何设置图例中线的长短粗细?如何去掉图例的方框?

legy = legend('line1 ','line2 ','line3','fontsize',10,...
    'position',[0.32 0.71 0.6 0.22]);
legy.ItemTokenSize = [15,15]; %设置线条长短,宽度
legend('boxoff') % 去方框

position’,[left bottom width height]
left: legend框距图片左边界的距离
bottom:距图片底部的距离
width: legend框的宽度
height:高度

2. gca

1).如何将图片四周大量空白填充?或如何让图形在显示窗口所占比例更大?

set(gca,'Position',[0.11 0.15 0.85 0.87]); 
%最小为0,最大为1

gca:get current axis, [left bottom width height]示意同上。

3.axis

1)如何指定坐标轴显示数值?

   set(gca, 'XTick', -pi:pi/2:pi);
   set(gca, 'XTickLabel', {'-pi','-pi/2','0','pi/2','pi'});
   or
   xticklabels({'0','\pi','2\pi','3\pi','4\pi','5\pi','6\pi'})
   xticks([0 5 10 15])
   xticks(0 : 10 100)

xtick表示显示刻度的位置,xticklabel表示显示的内容

2)如何将坐标轴说明文字倾斜?如何设置该文字的字体?

x1 = xlabel('\itX /\rmpixel');
y1 = ylabel('\itY /\rmpixel');
z1 = zlabel('Spectrum \it/\rm(\times10^3)');
set(x1, 'Rotation', -15);
set(y1, 'Rotation', 40);

a. rotation, 表示旋转文字,靠近坐标轴数字为正,远离为负。
b. \it: 使字体倾斜,例中的斜杠也倾斜
c. \rm: 设置正体

3).如何设置坐标轴说明文字的字号?

set(get(gca,'XLabel'), 'FontSize',7.5, 'Vertical', 'middle'); 

4.colorbar

1)如何设置彩色条的位置、字体、字号?

h1 = colorbar('east', 'AxisLocation', 'out',  'position', [cf cb cw ch], ...
'FontSize', 7.5,  'FontName','Times New Roman'); 

坐标内添加色度条,刻度在外,字号7.5,字体Time~。

2)如何在彩色条上设置文字?

%接上段
set(get(h1,'title'),'string','Phase \it/\rmrad');

添加文字,Phase /rad

5.设置图片尺寸,输出格式

set(gcf,'unit','centimeters','position',[20 15 6 7])
 %设置图片大小 6cm*7cm

猜你喜欢

转载自blog.csdn.net/qq_40797015/article/details/111041569