Matlab: summary of legend, axis coordinate setting, colorbar, export image format and other issues

1.legend

1). How to set the legend anywhere in the picture? How to set the length of the line in the legend? How to remove the box in the legend?

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: the distance between the legend box and the left edge of the image
bottom: the distance from the bottom of the image
width: the width of the legend box
height: height

2. gca

1). How to fill a lot of blanks around the picture? Or how to make the graphics occupy a larger proportion in the display window?

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

gca: get current axis, [left bottom width height] indicates the same as above.

3.axis

1) How to specify the coordinate axis display value?

   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 represents the position of the display scale, xticklabel represents the displayed content

2) How to tilt the description text of the coordinate axis? How to set the font of the text?

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, means to rotate the text, the number close to the coordinate axis is positive, and the number far away is negative.
b. \it: Make the font slanted, the slash in the example is also slanted
c. \rm: Set the normal font

3). How to set the font size of the coordinate axis description text?

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

4.colorbar

1) How to set the position, font and font size of the color bar?

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

Add chromaticity bar in the coordinates, scale outside, font size 7.5, font Time~.

2) How to set text on the color bar?

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

Add text, Phase /rad

5. Set the picture size and output format

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

Guess you like

Origin blog.csdn.net/qq_40797015/article/details/111041569