Overall conclusion: How MATLAB draws beautiful images

Source: Internet
Author: User
Tags cos uicontrol
How to determine the scale Size of the horizontal and vertical coordinates in the drawing command (self-defined range)
How to draw multiple curves in one coordinate and use different colors.
Hope to get the answer. Thank you !!!!!!!!!!!
Help plot
Help axis

Axis ('xlabel', 'ylabel ')

A1 = plot ();
Hlevels on
A2 = plot ();
Legend ([a1 a2], 'figure 1 name', 'figure 2 name ')
Hold off
More

X1 =-Pi: PI/12: PI;
X2 =-Pi: PI/12: PI;
Y1 = sin (X1 );
Y2 = cos (X2 );
Plot (x1, Y1, X2, Y2 );
Axis ([-2 * Pi 2 * pi-2 2]);
Xlabel ('x ');
Ylabel ('y ');
Title ('sin (x) & cos (x )');




FunctionAnd Graphic ControlFunctionAnd Operation and ControlMATLABDrawing or outputting a drawing in a drawing window is like a drawing.
2. InMATLABManage the graphic window by managing the handle of the graphic window;
3. The current window handle can beFunctionObtained by GCF;
4. At any time, only one window is the current graphic window (active window );
Figure (h) ---- set the window whose handle is H to the current window;
5. There are three ways to open a graphic window:
1) Call plottingFunctionAutomatically open;
2) Use File --- New --- figure to create a new image;
3) Open the figure command and close the command.
If a drawing window is opened before running the drawing programFunctionDirectly use
Opened graphical window. If multiple graphical windows exist before the program is run, and no window is specified
When the port is the current window, the last used window is the output graph of the current window.
6. graphic printing in the window: print items in the File menu of the graphic window.
7. You can set the parameters of the graphic object in the graphic window. The specific method is to edit the dish in the graphic window.
Select the properties item in the ticket to open the parameter settings window of the graphic object. You can set the owner of the object.
.
Ii. Coordinate System
1. A graphic must have its positioning system, I .e., the coordinate system;
2. There can be multiple coordinate systems in a graphic window, but there is only one current coordinate system;
3. Each coordinate system has a unique identifier, that is, the handle value;
4. The current coordinate system handle can beFunctionObtained by GCA;
5. Make the coordinate system of a handle identifier become the current coordinate system, which can be used as follows:Function:
1) define the coordinate range: GeneralMATLABAutomatically defines the coordinate range.
Suitable, available: Axis ([xmin, xmax, ymin, Ymax]) to reset;
29
2) coordinate axis control:MATLABThe default method is to draw the Coordinate System
. Axis off; axis on is used to display the coordinate axes.
(Default ).
3) normallyFunction
PlotFunctionThe basic call format is:
1. Plot (y) ------ draw a two-dimensional curve graph with vector y corresponding to the ordinal number of its elements. If Y is a complex vector,
Draw a two-dimensional curve for the real part of the virtual part.
For example, draw a single vector curve.
Y = [0 0.6 2.3 5 8.3 11.7 15 17.7 19.4 20];
Plot (y)
Because y vector has 10 elements, X coordinates are automatically defined as [1 2 3 4 5 6 7 8 9 10]. The image is:
12345678910
0
2
4
6
8
10
12
14
16
18
20
2. Plot (x, y) ------ plot the curve determined by X and Y.
1) if X and Y are two sets of vectors and their lengths are equal, plot (x, y) can intuitively plot
X coordinate. y indicates the X coordinate.
For example, draw a sine curve:
T =. * PI;
Y = sin (t );
Plot (T, Y)
2) when X is a vector and Y is a matrix in plot (x, y), the rows or columns in the Y matrix correspond
30
Curve of vector X. If the length of the row in array Y is the same as that of the X vector
Data is used as a set of drawing data. If the length of the column in array Y is the same as that of the X vector
The column data of Y is used as a set of drawing data. If the row of Y array is, the column is consistent with the length of X vector.
Same, each column of Y is used as a group of drawing data.
For example, the following program can plot three curves at the same time.MATLABWhen multiple curves are drawn
The color of each curve is automatically changed according to certain rules.
X = 0: PI/50: 2 * PI;
Y (1, :) = sin (X );
Y (2, :) = 0.6 * sin (X );
Y (2, :) = 0.3 * sin (X );
Plot (x, y)
Or you can use it like this:
X = 0: PI/50: 2 * PI;
Y = [sin (x); 0.6 * sin (x); 0.3 * sin (x)];
Plot (x, y)
01234567
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
3) If X and Y are matrices of the same size, the plot (x, y) plot the columns in Y corresponding to the columns in X
Graphics.
Example: x (1, :) = 0: PI/50: 2 * PI;
X (2, :) = PI/4: PI/50: 2 * PI + PI/4;
X (3, :) = PI/2: PI/50: 2 * PI + PI/2;
Y (1, :) = sin (x (1 ,:));
Y (2, :) = 0.6 * sin (X (2 ,:));
Y (3, :) = 0.3 * sin (x (3 ,:));
Plot (x, y)
X = x ';
Y = y ';
Figure
31
Plot (x, y)
In this example, X ------ 3X101, y ------ 3X101, so the first plot is drawn by Column
101 curves, 3 points each; and X' ------ 101x3, y' ------ 101x3, so the second plot
Draw 3 curves by column, with each 101 points.
012345678
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
012345678
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
3. Plot multiple groups of variables: plot (x1, Y1, option 1, X2, Y2, option 2 ,......)
In the above plot format, the option refers to the color, line type, and marking point of the drawn curve to distinguish multiple lines.
The property of the Set curve.MATLABWhen drawing multiple sets of variables, the curve can be different
Different line types and marked points are displayed. These options are shown in the following table:
Various color attribute options
Select meaning select meaning
'R' red 'M' pink
'G' green 'C' cyan
32
'B' blue 'W' white
'Y' yellow 'K' black
Various linear attribute options
Select meaning select meaning
'-'Solid line' -- 'dotted line
': 'Dot line'-.'
Various tag attribute options
Select meaning select meaning
'.' Draw data points with periods '^' draw data points with triangles
'+' Use '+' to draw data points 'V' use the lower triangle to draw data points
'*' Draw data points with '*'> 'draw data points with the right triangle
'.' Draw data points with '.' <'draw data points with the Left triangle
'S' or squar draw data points by square 'P' draw data points by five-star
'D' or diamond: Use a diamond to draw data points 'H'. Use a hexagonal star to draw data points.
These options can be used together. For example, '-. G' indicates to draw a green dot line, and' G + 'indicates to use a green dot line.
Draw a curve with the plus sign of the color.
Note: 1) the attribute symbols must be placed in the same string;
2) You can specify 2 ~ Three attributes;
3) it is irrelevant to the sequence;
4) The same attribute cannot have more than two.
For example, t =. * PI;
Y1 = sin (t );
Y2 = cos (t );
Y3 = sin (T). * Cos (t );
Plot (T, Y1, '-R', T, Y2,': G', T, Y3, '* B ')
The program can also be written as follows:
T =. * PI;
Y1 = sin (t );
Y2 = cos (t );
Y3 = sin (T). * Cos (t );
Plot (T, Y1, '-R ')
Hold on
Plot (T, Y2, ': G ')
Plot (T, Y3, '* B ')
Hold off
Note: InDrawingYou have already opened a graphical window, and thenDrawingThe system will automatically
You can erase the existing graphic objects in the coordinate system, but after you set hold on, you can keep the existing drawing objects in the coordinate system
.
33
01234567
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Figure ()
You can also set the linewidth to mark the edge color of a vertex.
(Markeredgecolor), markerfacecolor, and markersize)
Other drawing properties.
For example, set the line type, color, width, and color and size of the marking point of the drawing line.
T = 0: PI/20: PI;
Y = sin (4 * t). * sin (T)/2;
Plot (T, Y, '-BS', 'linewidth', 2,... % set the line width to 2
'Markeredgecolor', 'k',... % sets the color of the edge of the marking point to black.
'Markerfacecolor', 'y',... % sets the color of the markup point to yellow.
'Markersize', 10) % set the markup point size to 10
The plot is as follows:
00.511.522.533.5
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
34
4. Double Y axis drawing: plotyy ()FunctionFor example, plot, semilogx,
Loglog.
For example, draw a Double Y axis curve in a graphic window.
X = 0: 0. 3: 12;
Y = exp (-0.3 * X). * sin (x) + 0.5;
Plotyy (X, Y, X, Y, 'plot', 'stem ')
The figure is as follows:
024681012
0
0.5
1
1.5
024681012
0
0.5
1
1.5
Stem: draws a stem curve (a vertical line with a circle on the top ).
Drawing result: the two lines are automatically distinguished by different colors. The colors of the two coordinates are different from those of the line.
The Y coordinate on the left corresponds to a curve in the form of plot, and the Y coordinate on the Right corresponds
Is a stem curve.
Ii. Drawing the logarithm coordinate chartFunction: Semilogx, semilogy, and loglog
Number.
1) semilogx () ------ draw a logarithm coordinate graph with the X axis as the logarithm coordinate axis.
The call format is: semilogx (X, Y, 'Property options ')
The property options are the same as those of plot.FunctionOnly logarithm transformation is performed on the X-axis, and the y-axis is still linear.
2) semilogy () ------ draw a logarithm coordinate graph with the Y axis as the logarithm coordinate axis.
The call format is: semilogy (X, Y, 'Property options ')
TheFunctionPerform logarithm transformation on the horizontal and vertical coordinates respectively.
Example: x = 0: 0. * PI;
Y = cos (X/3) + 1/9;
Subplot (221), semilogx (x, y );
Subplot (222), semilogy (x, y );
Subplot (223), loglog (x, y );
4)Function: Logspace ()Function, Which can be divided by logarithm and other distance
To generate a vector. The Calling format is:
X = logspace (x1, x2, n)
Here, x1 represents the starting point of the vector; x2 represents the end point of the vector; n represents
Number (generally not given, the default value is 50 ).
In the control system analysis, this method is generally used to construct the frequency vector W.
Also mentioned.
3. Create a polar chartFunctionThe call format is as follows:
Polar (Theta, rock, 'attribute options') ------ Theta: angle vector, Rock: amplitude vector, attribute
Content and plotFunctionBasically consistent.
For example, if the polar chart model is 3145/)/cos (+ = θ P,], and [π θ 80ε, then the polar chart is drawn.
Program: Theta =. * PI;
P = cos (5 * theta)/4) + 1/3;
Polar (Theta, P)
0.5
1
1.5
30
210
60
240
90
270
120
300
150
330
1800
4. Draw multiple subgraphs: subplot ()MATLABMultiple subgraphs can be drawn in a graphic window (for example
The window can be divided into nxm parts.
Use subplot to split the graph windowDrawingThe code of the part, indicating the number of images. The nmk three numbers can be written in a row, not in the middle.
Separate symbols.
For example, to divide the window into 2x2 = 4 parts, you can write it as follows:
Subplot (2, 2, 1), plot (......)
Subplot (2, 2 ),......
Subplot (2, 2, 3 ),......
Subplot (2, 2, 4 ),......
221 222
223 224
Note: subplotDrawingFunction, only split the window.
Section 3 graphic modification and labeling
FunctionModify the drawn image.Function
The call format is title ('string') ------ the string can be written in Chinese.
For example, title ('my own plot ')
2) Coordinate Axis Description: xlabel and ylabelFunction
A. TextFunction: Write instructions in the coordinate system at the specified position.
Format: Text (x1, Y1, 'string', 'options ')
X1, Y1 are the coordinates of the specified point; 'string' is the text to be labeled; 'options' determines X1, Y1
If no options are available, the coordinate units of X1 and Y1 are the same as those in the graph. If the options are 'scs ',
Then X1 and Y1 indicate the relative coordinates of the canonicalized window. The range is 0 to 1.
(1, 1)
Standardization window
(0, 0)
37
For example, text (1, 2, 'sine curve ')
B. gtextFunctionIn the graphic window, There is a cross line that moves with the mouse,
Move the mouse to move the intersection of the cross line to the appropriate position, click the left mouse button, gtext Parameter
The string is marked on this position.
4) Add a grid to the image: GridFunctionApplication Example:
For example, add the axis identifier and title in the image and add the text to any position in the image.
T = 0: PI/100:2 * PI;
Y = sin (t );
Plot (T, Y), grid,
Axis ([0 2 * pi-1 1])
Xlabel ('0 Leq itt rm Leq PI ', 'fontsize', 16)
Ylabel ('sin (t) ', 'fontsize', 20)
Title ('sineFunctionGraphics
Partition sin (t) = 0
← Sin (t) = 0.707
Sin (t) =-0.707 →
5) Add the legend box to the graph: LegendFunction
The call format is:
A. Legend ('string 1', 'string 2 ',......) ------ Take string 1, string 2 ...... Work
38
The legend marked for the image.
B. Legend ('string 1', 'string 2 ',......, Pos) ------ POS specifies the position displayed in the legend box.
The legend box is prefixed with six display locations:
0 ------ get the best position;
1 ------ upper right corner (default );
2 ------ upper left corner;
3 ------ lower left corner;
4 ------ bottom right corner;
-1 ------ right of the graph.
Example: Add a legend to the graph.
X = 0: PI/10:2 * PI;
Y1 = sin (X );
Y2 = 0.6 * sin (X );
Y3 = 0.3 * sin (X );
Plot (x, Y1, X, Y2, '-O', X, Y3 ,'-*')
Legend ('curve 1', 'curve 2', 'curve 3 ')
The plot is as follows:
02468
-1
-0.5
0
0.5
1
Curve 1
Curve 2
Curve 3
6) Click ginput.Function
Format: [x, y, button] = ginput (N)
Where: N indicates the number of selected points, x, y indicates a vector, and X indicates the abscissa of the selected N points;
Y is the ordinate of the selected N points.
The button is an n-dimensional vector and is the label of the mouse key corresponding to the selected N points:
1 ------ left click;
2 ------ middle key;
3 ------ right-click.
You can use different mouse keys to select different points.
This statement can be placed after the drawing statement. It can operate on the drawing and select what you feel.
Interest points, such as the peak point and the point that reaches the steady state value, give the coordinates of the points and find the system's
Performance indicators.
39
Section 4MATLABGraphical objects refer to the most basic and underlying units in the graphic system. These objects include:
Screen (Root), graphic window (figures), axis (axes), control (uicontrol), menu (uimenu ),
Lines, blocks, surface, images, text, and so on.
Based on the relationship between objects, the tree hierarchy is shown as follows:
Root
Figures
Axes uicontrol uimenu uicontextmenu (Object menu)
Images line patch surface text
To modify and control various graphical objects, useMATLABEach graphic object is assigned a unique identifier when it is created.
Is the handle of the object.
The handle value can be a number or a vector. For example, each computer's root object only has
One, its handle is always 0, and the handle of the graphic window is always a positive integer, it identifies the serial number of the graphic window
And so on.
You can use a handle to manipulate the attributes of an existing graphic object, especially for a specified graphic object.
Operations on the image handle do not affect other graphical objects that exist at the same time. This is very important.
1. You can use the following method to modify a graphic object:Function: Used to set the attributes of the graphic object indicated by the handle.
SetFunction: Gets the current value of the specified property of the graphic object of the specified handle.
Format: Get (handle, 'Property name ')
For example: Get (GCA, 'xcolor') ------ obtain the current color attribute value of the X axis.
After execution, you can return the current color attribute value of the X axis [0, 0] (black ).
3) If no handle is set, you can use the followingFunctionObtain:
GCF: Get the handle of the current graph window;
GCA: Get the handle of the current axis object;
GCO: Get the handle of the current object.
For example:
A. to modify the background color of the graphic window, you can:
Set (GCF, 'color', [, 1]) ------ set the background color of the graphic window to white
B. change the color of the current X axis to green. Available:
Set (GCA, 'xcolor', [0, 1])
40
C. You can also define the scale displayed on the coordinate axis:
T =-Pi: PI/20: PI;
Y = sin (t );
Plot (T, Y)
Set (GCA, 'xticick', [-Pi: PI/2: Pi], 'xticicklab', ['-Pi', '-PI/2', '0 ', 'Pi/2', 'Pi '])
-Pi-PI/20pi/2PI
-1
-0.5
0
0.5
1
In this example, the 'xticket' attribute is used to set the position of the X axis Scale (from-pi ~ Pi, interval PI/2, set in total
Use 'xticicklabel' to specify the value of the scale.
Therefore, set ['-Pi', '-PI/2', '0', 'Pi/2', 'Pi'] Five scale values.
2. Some common attributes are as follows:
1) Box attribute: determines whether the coordinate axis is in the box format. The option is 'on' (with a box ),
'Off' (no box );
2) 'rorder' property: sets the color sequence of multiple curves. The default value is:
[1 0; 1 0 1; 0 1 1; 1 0 0; 0 1 0; 0 0 0 1]
Yellow, pink, blue, red, green, blue
Color vector: [1 1] ------ white; [0 0 0] ------ black.
3) axis direction attributes: 'xdir', 'ydir', and 'zdir'. The options are:
'Normal' ------ normal
'Reverse' ------ reverse
4) axis color and line type attributes: 'xcolor', 'ycolor', 'zcolor' ------ axis color,
Color Vector




How can I scale a curve on a graph ???
I just want to mark 30.60.90 ~ on some specific vertex edges ~ 7200 incremental Data]
There are 96 points to mark !!
Can only text be painted one by one ??
Please help me.
Can text be added to the loop statement?




Url = 'HTTP: // hiphotos.baidu.com/baidu/pic/item/826405f4715fb763dcc47472.jpg ';
Im = imread (URL );
Imshow (IM)

Then enter:

Text (100,100, '\ o', 'color', 'red ');
MATLAB: read an image using imread. I want to mark some coordinate points on the image. For example, the points with the coordinate value (100,100) are marked in red circles. What command statements are used for implementation?


Use subplot to create the following four curves in an image window, and add the superlabel for each image
Question:
1) probability curve y = e ^ (-x ^ 2)
X
2) Four-leaf Rose Line P = sin2 θ
3) Leaf Shape Line X = 3 t/(1 + t ^ 3)
Y = 3 t ^ 2/(1 + t ^ 3)
4) x = A (t-Sint), Y = a (1-cost), and tε [π].



Second

Draw curves Y1 = 0.2e-0.5 xcos (4pix) and Y1 = 2e-0.5xcos (pix) with different line types and colors in the same coordinate to mark the intersection of the two curves.

Pi is the circumference Rate


Very urgent. Thank you.

CLC; clear
Subplot (2, 2, 1)
Ezplot ('exp (-x ^ 2 )')
Subplot (2, 2)
Ezpolar ('sin (2 * t )')
Subplot (2, 2, 3)
T = 0: PI/100:2 * PI;
X = 3 * T./(1 + T. ^ 3 );
Y = 3 * T. ^ 2./(1 + T. ^ 3 );
Plot (x, y)
Subplot (2, 2, 4)
A = 2;
X1 = A * (t-sin (t ));
Y1 = A * (1-cos (t ));
Plot (x1, Y1)

% [2]
X = 0: PI/500: 2 * PI;
Y1 = 0.2 * exp (1)-0.5 * X. * Cos (4 * pI * X );
Y2 = 2 * exp (1)-0.5 * X. * Cos (pI * X );
Figure
Plot (x, [Y1; y2])

'Linewidth' ------ the line width of the axis. The value is a number.
'Xgrid', 'ygrid', 'zgrid' ------ on the coordinate axis is
Whether to add a grid. The values are 'on' and 'off '.
5) ruler attribute of the coordinate axis: 'xticket', 'yzick', and 'zticket' ------ scale position, value:
Vector
'Xticicklabel', 'yzicklabel', 'yzicklabel' ------ axis
The scale symbol. Its value is the same as the scale position vector.
Small (with the same number of vectors) vectors.
5) font setting attribute: 'fontange' ------ set the font angle with the options:
41
'Normal' ------ normal;
'Italic '------ italic;
'Oblique' ------ skew;
'Fontname' ------ font name;
'Fontsize' ------ font size
'Fontweight '------ font weight, option: 'light ',
'Normal', 'bold'
42

Via from: http://www.eefocus.com/sunshine/blog/09-05/170813_8c98c.html

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.