MATLAB分享第四弹

今天是正月初八,和大家继续分享MATLAB

Multiple Figures

Create a figure window bu calling figure

x = -10:0.1:10;

y1 = x.^2 - 8;

y2 = exp(x);

figure, plot(x, y1);

figure, plot(x, y2);

Be careful when using gcf handle(gca) while there exist multiple figures.

所以在这里弄清楚current axes和 current figure 还是十分有必要的.

Figure Position and Size

figure('position',[left,bottom,width, height]);

Several Plots in one Figure

Several small plots"in a figure"

subplot(m, n, 1);

其中的m referred to the number of rows

n referred to the number of columns

后面的数值代表1-6.就是很多图拼到了一起,代表着一种排列的方式,这样画的时候就不容易画错.

t = 0 : 0.1: 2*pi;

x = 3* cos(t);

y = sin(t);

subplot(2,2,1); plot(x,y) axis normal

subplot(2,2,2); plot(x,y) axis square

subplot(2,2,3); plot(x,y);axis equal

subplot(2,2,4); plot(x,y); axis equal tight

grid on/off

Make the grid visible or invisible

Make the box visible or invisible

axis on/off

Make the axes visible or invisible

axis normal

Automatically adjust the aspect ratio of the axes and the relative scaling of the data units

axis square

Make the current axis region square

Set the aspect ratio so that the data units are the same in every direction

axis equal tight

Set the axis limits to the range of the data.

Let the plot box fits tightly around the data

Place the origin of the corresponding system in the upper left corner

Place the origin in the lower left corner.

了解了这么多有关绘图的基本操作,那么接下来怎么样将绘制好的图形存储进文件当中呢:

Saving Figures into Files

saves(gcf,'<filename>','<formattype>");

Option     Bitmap Image Format

'jpeg'        JPEG 24-bit

'png'          PNG 24-bit

'tiff"           TIFF 24-bit(compressed)

'bmpmono' BMP Monochrome

'bmp'         BMP 24-bit

'bmp256'   BMP 8-bit(256 color, used a fixed colormap)

'pdf'   Full page portable Document Format(PDF) color

'eps'     Encapsulated Postscript(EPS) Level 3 black and white

'epsc' Encapsulated Postscript(EPS) Level 3 color

'meta' Enhanced Metafile(Windows only)

'svg' (scalable vector graphics)

'ps' (Full-page postScript(PS) Level 3 black and white

'psc' Full-page Postscript(PS) Level 3 color

To control size and resolution,use print instead:

gcf 主要是写入位图和矢量图

有人可能会问,左上角的saveas不是可以直接保存嘛?

是的,当时那样保存的解析度不够高,如果我们需要高解析度的图片的话,还是很有必要用我的这种操作去限制解析度的.

好了,今天就分享到这了.