The functions of the subplot function in MATLAB are similar to Python

Source: Internet
Author: User
Tags cos dashed line

Original: http://blog.163.com/my_it_dream_pwj/blog/static/17841430520112294342649/

like in Python

Subplot

Function

Split figure, create sub-coordinate system

Grammar

h = subplot (m,n,p) or subplot (MNP)
Subplot (m,n,p, ' replace ')
Subplot (M,N,P)
Subplot (h)
Subplot (' Position ', [left bottom width height])
Subplot (..., Prop1, value1, PROP2, value2, ...)
h = Subplot (...)

Describe

h = subplot (m,n,p)/subplot (MNP) divides the figure into an MXN block, creates a coordinate system in block p, and returns its handle. When m,n,p<10, it can be simplified to subplot (MNP) or subplot MNP

(Note: subplot (m,n,p) or subplot (MNP) This function is most commonly used: subplot is a tool that moves multiple drawings onto a flat surface. where m indicates that the graph is lined with m rows, n indicates that the graph is in n columns, that is, the entire figure has n graphs lined up in rows, a total of M rows, if the first number is 2 means a 2-row graph. P is the point where you want to draw the curve to the figure, and the last one if 1 means the first position from left to right. )

Subplot (m,n,p, ' replace ') if the specified coordinate system already exists, create a new coordinate system to replace it

Subplot (m,n,p) at this point P is a vector, which means that the small blocks specified in P are combined into a large chunk to create a coordinate system, and the small blocks specified in P can be discontinuous or even unconnected.  

For example, subplot (2,3,[2 5]) means that the 2nd and 5 small pieces are connected to a large chunk, subplot (2,3,[2 6]) because 2 and 6 are not contiguous, it is said that the 2nd, 3, 5 and 64 blocks are connected to a large chunk, equivalent to subplot (2,3,[2 3 5 6])

Subplot (h) set the coordinate system H to the current coordinate system, equivalent to Axes (h)

Subplot (' Position ', [left bottom width height]) creates a new coordinate system at the specified location, equivalent to axes (' Position ', [left Bottom Width height])

Subplot (..., Prop1, value1, PROP2, value2, ...) when creating a coordinate system, set related properties at the same time, axes properties see Appendix  

h = Subplot (...) returns the handle of the created coordinate system

Attention

1) using subplot new axes block if you overlap an existing block, MATLAB will delete the existing axes and create a new axes, unless it already exists and the axes you want to create is fully coincident (this is equivalent to placing it in the current coordinate system), and if you want to delete the rebuild, you need to use ' replace ' parameter

2) subplot (1,1,1) empties all coordinate system objects in the current window and creates a default coordinate system. Note that at this point subplot (1,1,1) and subplot (111) are not completely equivalent, and after the execution of subplot (111), there is no visual reaction, it simply prompts the figure to execute the empty graphical command before the next call to the drawing command CLF Reset, Then create a default coordinate system. That is, subplot (111) is equivalent to separating the operations of subplot (1,1,1). Because subplot (111) does not create a new coordinate system after execution, it is impossible to return a handle, that is, H=subplot (111) is wrong

Example 1:

T=0:0.001:1;
Y1=sin (10*t);
Y2=sin (15*t);
Subplot (211)
Plot (T,Y1)
Subplot (212)
Plot (T,y2)

Example 2:

x=20:10:20000;
Y=rand (Size (x));

Subplot (3,2,1)
Plot (x)
Title (' Default format ')

Subplot (3,2,2)
Plot (x)
Set (GCA, ' XTick ', [1 3 6 8]);
Set (GCA, ' Ytick ', []);
Title (' x custom interval, y off ')

Subplot (3,2,3)
Plot (x)
Set (GCA, ' XTick ', [1 3 6 8]);
Set (GCA, ' Xticklabel ', sprintf ('. 4f| ', Get (GCA, ' XTick ')))
Set (GCA, ' Ytick ', [2 4 5 7]);
Set (GCA, ' Yticklabel ', {' n ', ' Four ', ' Five ', ' Seven '});
Title (' XY custom interval, precision and display mode ')

Subplot (3,2,4)
Plot (x)
Set (GCA, ' Xminortick ', ' on ');%style 5
Set (GCA, ' ticklength ', [0.05 0.025]);
Set (GCA, ' tickdir ', ' out ');
Title (' XY coordinate scale display mode ')

Subplot (3,2,5)
Plot (x)
Set (GCA, ' XTick ', [min (x) (max (x) +min (x))/2 max (x)]);
Set (GCA, ' Ytick ', [min (x) (max (x) +min (x))/2 max (x)]);
Title (' Standard 3-point display used in paper ')

Subplot (3,2,6)
SEMILOGX (x, y);
Set (GCA, ' Xlim ', [20 20000]);
Set (GCA, ' Xminortick ', ' off ');
Set (GCA, ' XTick ', [20 31.5 63 125 250 500 1000 2000 4000 8000 16000]);
Set (GCA, ' XGrid ', ' on ');
Set (GCA, ' Xminorgrid ', ' off ');
Title (' Custom grid display ')

To supplement other plot usages:Plot to build a vector or matrix. The graphic character color character of each team vector
Loglog x, y axes are logarithmic scales to create a graph y yellow. Point
SEMILOGX x-axis for logarithmic scale, y-axis scale drawing graph K black O-circle
Semilogy y-axis for logarithmic scaling, x-axis Scaling drawing W white x x
Title to graphics plus heading B Blue + +
Xlabel x-axis marked G-Green * *
Ylabel y-axis with red-solid line
Text in the position specified by the graphic add a literal string C bright cyan: Dot Line
Gtext the position of the mouse with the text string M manganese purple-. Dot Dotted Line
Grid open gridlines-Dashed line
The hold command is used to add a new figure to a drawn graphic 1) x=0:0.001:10; % 0 to 10 of 1000 points (every 0.001 draws a point) x-coordinates
Y=sin (x); % corresponding y-coordinates
Plot (x, y); % drawing
Note: Matlab drawing is actually a stroke line, so if the point obtained is not dense, the drawing is a linear chart, please test
2) Y=sin (10*x);
Plot (x, Y, ' r: ', X, y, ' B ')% draw two functions at a time
3) To change the color, add the relevant string to the following tag pairs:
X=0:0.01:10;
Plot (X,sin (x), ' R ')
4) To change both the color and the Linetype state (line style), you can also add the relevant strings to the coordinate pairs:
Plot (X,sin (x), ' r* ')
5) Use Axis ([Xmin,xmax,ymin,ymax]) function to adjust the range of the axis
Axis ([0,6,-1.5,1])
6) Matlab can also add various annotations and processing of graphics: (see table above)
Xlabel (' x-axis '); % x Axis annotations
Ylabel (' Y axis '); % y-axis annotations
Title (' cosine function '); % Graphics title
Legend (' y = cos (x) '); % Graphics annotations
Gtext (' y = cos (x) '); % graphical annotations, positioning the annotation position with the mouse
Grid on; % Display Gridlines
7) Draw Ellipse
A = [0:pi/50:2*pi] '; % angle
X = cos (a); % parametric equation
Y = sin (a) * *;
Plot (x, y);
Xlabel (' x '), Ylabel (' Y ');
Title (' Ellipse ')
8) Draw the curve of the function at 0≤x≤1.
X=0:0.1:1
Y=x.*exp (-X)% Why use point arithmetic? What if it doesn't?
Plot (x, y), Xlabel (' x '), Ylabel (' y '), title (' Y=x*exp (x) ')
9) Draw the attenuation oscillation curve with its envelope line and. The range of values for T is [0, 4π].
T=0:pi/50:4*pi;
Y0=exp (-T/3);
Y=exp (-T/3). *sin (3*t);
Plot (T,y, '-R ', T,y0, ': B ', T,-y0, ': B ')%-R denotes a solid red line,: B denotes a blue dot line, looks at the table
Grid
10) Set up several coordinate systems on the same screen, with subplot (m,n,p) command; Divide a picture into MXN graphics area, p represents the current region number, and draws a diagram in each region, as
X=linspace (0,2*pi,30); Y=sin (x); Z=cos (x);
U=2*sin (x). *cos (x); V=sin (x)./cos (x);
Subplot (2,2,1), plot (x, y), Axis ([0 2*pi-1 1]), title (' Sin (x) ')
Subplot (2,2,2), Plot (x,z), axis ([0 2*pi-1 1]), title (' cos (x) ')
Subplot (2,2,3), Plot (x,u), axis ([0 2*pi-1 1]), title (' 2sin (x) cos (x) ')
Subplot (2,2,4), Plot (x,v), axis ([0 2*pi-20]), title (' Sin (x)/cos (x) ') Three-dimensional graphics
11) Three-dimensional helix:
T=0:pi/50:10*pi;
Plot3 (sin (t), cos (t), T)% parametric equation
Grid% Add grid
T=linspace (0,20*PI, 501);
PLOT3 (T.*sin (t), T.*cos (t), T); % Attention Point Multiply
You can also draw two curves at the same time, the format is similar to the two-dimensional situation, this is not an example.
13) Drawing surfaces with mesh commands
Draw a stereoscopic network diagram formed by a function:
A=linspace (-2, 2, 25); % takes 25 points from ( -2,2) on the x-axis
B=linspace (-2, 2, 25); % take 25 points on y-axis
[X,y]=meshgrid (A, b); % x and y are 21x21 matrices.
Z=x.*exp (-x.^2-y.^2); % calculates the function value, Z is also the matrix of the 21x21
Mesh (x, y, z); % draw a stereo Network diagram
Surf and mesh use similar:
A=linspace (-2, 2, 25); % take 25 points on the x-axis
B=linspace (-2, 2, 25); % take 25 points on y-axis
[X,y]=meshgrid (A, b); % x and y are 21x21 matrices.
Z=x.*exp (-x.^2-y.^2); % calculates the function value, Z is also the matrix of the 21x21
Surf (x, y, z); % draw a cubic surface chart

The functions of the subplot function in MATLAB are similar to Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.