Control and representation of graphics (figure control and representation)
The functions and commands provided by MATLAB for graphical control:
Axis: Manually select an axis size.
CLF: Clear the graphics window.
Ginput: Use the mouse crosshair input.
Hold: Keep the graphic.
SHG: Displays the graphics window.
Subplot: Divides the graphics window into N-Block sub-windows.
1. graphics window (Figure windows)
(1). Creation and selection of the graphics window (Creating and selecting of Figure window)
Figure (N): Used to create a graphics window for the current drawing, and each time a figure is run, a new graphics window is created, and N represents the nth
window, if the window defines a handle, you can also use figure (h) to take the window of the handle H as the current window.
CLF: Used to clear the contents of the current graphics window.
SHG: Used to display the current graphics window.
(2). Draw multiple sub-shapes in one graphics window (Drawing several subfigures in a single window)
Subplot (m,n,p): divides the window into MXN small window, and the first window as the current window.
Example: Display 4 graphs in the same graphics window.
T=0:pi/20:2*pi; [X,y]=meshgrid (t);
Subplot (2,2,1); Plot (sin (t), cos (t)); Axis equal
Subplot (2,2,2); Z=sin (x) +cos (y); Plot (t,z); Axis ([0 2*pi–2 2])
Subplot (2,2,3); Z=sin (x). *cos (y); Plot (t,z); Axis ([0 2*pi–1 1])
Subplot (2,2,4); Z=sin (x). ^2-cos (y). ^2; Plot (t,z); Axis ([0 2*pi–1 1])
(3). Drawing on an existing graph (Drawing a figure on the figures was existed)
On: Continue drawing on an existing graph;
Hold off: Command ends to continue drawing.
Example: the contour map of the peaks function is drawn together with the pseudo-color.
[X,y,z]=peaks; % produces a double-variable array
Contour (x,y,z,20, ' k ')% draw contours
On
Pcolor (x, y, z)% plotting pseudo-color graphs
Shading Interp% surface color rendering
Hold off
2. Axis control Command (commands)
multiple invocation formats for axis functions that control the nature of coordinates:
Axis (xmin xmax ymin ymax): Specifies the scale range of the two-dimensional graphics x and y axes,
Axis Auto: Set axis to auto scale (default)
Axis manual (or axis): Maintain scale does not vary with data size
Axis tight: The size of the data is the range of the axis
Axis ij: Sets the origin of the axis in the upper-left corner, I is the ordinate, J is the horizontal point
Axis XY: Return the axis to the Cartesian coordinate system
Axis equal: Make axis scale increments the same
Axis square: Make each axis the same length, but the scale increment may not be the same
Axis Normal: Automatically adjusts the external ratio of the axis to the data to invalidate other settings
Axis off: Make axes invisible
Axis on: Show axis
(1) Range of axes (Domain of coordinates axis)
The two-dimensional graphics axis range is automatically set according to the size of the data by default, and can be defined by using axis (xmin xmax ymin ymax), if you want to change it.
Example: Define the effect of the Axis range on the viewing graph.
X=0:.01:PI/2; Figure (1); Plot (X,tan (x), '-ro ')%ymax=tan (1.57), while the other data is small, the result
% makes graphics difficult to observe and judge.
Figure (2); Plot (X,tan (x), '-ro '); Axis ([0, pi/2,0,5])% controls the range of the axes to get more satisfactory drawing results
(2) The effect of the scale on the drawing result (Effect of display scaling on plotting results)
Example: comparison ( Default, Axis Square, axis equal, axis tight) display the results in several different ways.
T=0:pi/20:2*pi; figure (1);
Subplot (2,1,1); plot (sin (t), 2*cos (t)), grid on % graph scale in default state
subplot (2,1,2); plot (sin (t), Cos (t)); Axis Square; Grid on % Square display scale
figure (2)
subplot (1,2,1); plot (sin (t), 2*cos (t)), axis equal; grid on & nbsp; % has an equal scale scale of
subplot (1,2,2); plot (sin (t), 2*cos (t)), axis tight; grid on & nbsp; % condensed form
3. Graphic callout (marking on the figure): Graphical dimensioning method for MATLAB (table 6-7)
title: title,
xlabel:x axis callout,
Ylabel:y axis Callout ,
Text: Labels for any positioning
gtext: Mouse positioned callout,
Legent: Callout legend
Graphic annotations can use letters, numbers, Chinese characters, or the Greek alphabet in a prescribed way. For example: \pi means that π,\leq means ≤,\rm that the following word reverts to traditional word, \it represents italic, FontSize indicates the size of the font, FontName indicates the type of font, and so on.
You can use the Insert menu of the graphics window, you can also use the property editor, and you can use the method of the function input to annotate, and the following describes how to use the related function.
(1). Fill axis identification and graphics title (Add axis labels and title of figure)
Fill axis identification: xlabel (' s '), Ylabel (' s ')
Graphic Title: Title (' s ')
Example: Fill in the axis and graphic title.
T=0:pi/100:2*pi;y=sin (t);
Plot (T,y)
Axis ([0 2*pi,-1 1])
Xlabel (' 0 \leq \itt \rm \leq \pi ', ' FontSize ', 16)
Ylabel (' sin (t) ', ' FontSize ', 20)
Title (' sine function graph ', ' fontname ', ' script ', ' FontSize ', 20)
(2). Fill text (Add text in the figure)
text (x, y, ' string ')
Example: In the Add statement.
T=0:pi/100:2*pi;
Y=sin (t);
Plot (t,y)
axis ([0 2*pi,-1 1])
Xlabel (' 0 \leq \itt \rm \leq \pi ', ' FontSize ', 16)
ylabel (' sin (t) ', ' FontSize ', ')
title (' sine function graph ', ' fontname ', ' script ', ' FontSize ', ')
text (3*pi/4,sin (3*PI/4), ' \leftarrowsin (t) =0.707 ', ' FontSize ', +)
text (Pi,sin (pi), ' \leftarrowsin (t) =0 ', ' FontSize ', +)
text (5*pi/4,sin (5*PI/4), ' Sin (t) =-0.707\rightarrow ', ' FontSize ',,...
' HorizontalAlignment ', ' right ')
In the sentence:
Leftarrow to add a left arrow
RightArrow to add a right arrow
HorizontalAlignment for right-aligned horizontal arrangement
gtext (' string '): Fill the text with the mouse directly at the specified position on the graphics window.
Cases:
T=0:pi/100:2*pi;
Y=sin (t);
Plot (T,y)
Axis ([0 2*pi,-1 1])
Xlabel (' 0 \leq \itt \rm \leq \pi ', ' FontSize ', 16)
Ylabel (' sin (t) ', ' FontSize ', 20)
Title (' sine function graph ', ' fontname ', ' script ', ' FontSize ', 20)
Gtext (' MATLAB ')
(3). Specify the Tex character
example: Specify Tex characters in the title
t=0:pi/100:2*pi;
alpha=-0.8;
beta=15;
Y=sin (beta*t). *exp (alpha*t);
Plot (t,y)
title (' {\itae}^{-\it\alpha\itt}sin\it\beta{\itt}\it\alpha <<\it\beta ')
xlabel (' Time \mus. '),
ylabel (' amplitude ')
The string in title is represented by the aeαt sinβt α<<β
Italic ae superscript italic αt italic βt italic α italic β
(4). Add a legend box to the drawing (add legend in the figure)
Legend (string 1, String 2, ...)
Example: Add a legend description to the current drawing.
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 ')
Legend (' Boxoff ')
See the other functions of the Legend function (table 6-8)
4. Line form and colors (Style and color of plot)
(1). The form of the graph line: (style of plot)
Four lines: Solid line '-', dashed '--', Dotted line ': ', dot dash '-'.
Mark Point type : Dot '. ', round ' o ', plus ' + ', asterisk ' * ', x ' x ', square ' s ', Diamond ' d ', hexagram ' h '
Upper triangle ' ^ ', lower triangle ' V ', left triangle ' < ', right triangle ' > ', positive Pentagon ' P '
command: plot (x, Y, '-'), plot (x1,y1, ': ', x2,y2, ' * ')
Example 1: Choose a different linear drawing.
T=0:pi/100:2*pi; Y=sin (t); Y2=sin (t-0.25); Y3=sin (t-0.5);
Plot (T,y, '-', t,y2, '-', T,y3, ': ')
Example 2: Choose a different marker point drawing.
T=0:pi/20:2*pi; x=t.^3; Y=sin (t); Plot (x, y, ' o ')
(2). Color of line (color of plot)
Available Colors: red R, Green G, blue B, yellow y, pink m, cyan C, Black K.
Example: T=0:PI/20:2*PI;
Y=sin (t); Plot (x, Y, ' R '), plot (x, y, ' g+ ')
(3). Other properties of the graph line (other characters of plot)
to set the width of the drawing line: ' LineWidth '
edge Color of marker points: ' Markeredgecolor '
Fill Color: ' Markerfacecolor '
the size of the marker point: ' Markersize '
Example: Set the line shape, color, width, color, and size of the marker points.
T=0:pi/20:pi; Y=sin (4*t). *sin (t)/2;
Plot (t,y, '-bs ', ' linewidth ', 2, ' markeredgecolor ', ' k ', ' markerfacecolor ', ' y ', ' markersize ', 10);
MATLAB Drawing Basic Control commands