Function
2D Curve Drawing
grammar
1 2 3 4 5 6 7 plot(Y) plot(X1,Y1,...) plot(X1,Y1,LineSpec,...) plot(...,'PropertyName',PropertyValue,...) plot(axes_handle,...) h = plot(...) hlines = plot('v6',...)
describe
plot(Y) If Y is an m×n array, take 1:m as the X abscissa, and each column element in Y is the Y coordinate, and draw n curves; if Y is an n×1 or 1×n vector, Then draw a curve with 1:n as the abscissa and Y as the coordinate table; if Y is a complex number, plot(Y) is equivalent to plot(real(Y),imag(Y)); in other cases, ignore The imaginary part in the coordinate data.
plot(X1,Y1,...) If both X and Y are arrays, draw the coordinate data by column, and they must have the same size; if one of X and Y is a vector and the other is an array, X and Y The directions of equal size in the middle correspond to drawing multiple curves; if one of X and Y is a scalar and the other is a vector, then discrete points along the vertical X or Y axis will be drawn.
X |
Y |
|
Remark |
m×n |
m×n |
Draw n curves by taking coordinate data by column |
X and Y must have the same dimensions |
1×n or n×1 |
m×n or n×m |
Automatically match the size and draw m curves in the same direction |
Any four combinations have the same effect |
m×n or n×m |
1×n or n×1 |
Ditto |
Ditto |
1×1 |
1×n or n×1 |
Plot vertical X-axis discrete points |
Y can be any vector |
1×n or n×1 |
1×1 |
Plot vertical Y-axis discrete points |
X can be any vector |
plot(X1,Y1,LineSpec,...) specifies the curve properties of the curve through the parameter LineSpec, which includes line type, marker and color. The plot function supports plotting any group of graphs at the same time
1 plot(X1,Y1,LineSpec1,X2,Y2,LineSpec2,...)
is exactly equivalent to
1 2 3 4 5 plot(X1,Y1,LineSpec1,...) hlod all plot(X2,Y2,LineSpec2,...)
The linetype properties available in MATLAB are:
line type |
illustrate |
marker |
illustrate |
color |
illustrate |
- |
solid line (default) |
+ |
plus sign |
r |
red |
-- |
double dash |
o |
hollow circle |
g |
green |
: |
dotted line |
* |
Asterisk |
b |
blue |
:. |
Dotted line |
. |
filled circle |
c |
green |
|
|
x |
cross sign |
m |
magenta |
|
|
s |
square |
y |
yellow |
|
|
d |
diamond |
k |
black |
|
|
^ |
upper triangle |
w |
White |
|
|
v |
lower triangle |
|
|
|
|
> |
right triangle |
|
|
|
|
< |
left triangle |
|
|
|
|
p |
Pentagram |
|
|
|
|
h |
hexagon |
|
|
It should be noted that when the three attributes of curve line type, identifier and color are set in LineSpec, the order of control characters is not limited and can be omitted or partially omitted. That is to say, 'r-.*', '-.r*', '*-.r' and other forms are equivalent, which means that each node is connected by a red dot-dash line, and each node is marked with "*".
1 2 3 plot(...,'PropertyName',PropertyValue,...)set by plot properties of all created curve handle objects, Line See the appendix for object attributes and attribute values, and refer to the following examples for specific settings. Of course, you can use set/get Make settings. plot(axes_handle,...)Specify the coordinate system, that is, in axes_handle Drawing in the coordinate system, defaults to when not specified gca .
h = plot(...) returns handles to all curve handle objects created by plot. Each curve corresponds to a handle, if there are n curves, h is an n×1 array.
Notice
When drawing multiple curves at the same time, if no curve attribute is specified, the plot cycle uses the two attributes ColorOrder and LineStyleOrder in the current coordinate system in order.
By default, MATLAB automatically resets ColorOrder and LineStyleOrder to DefaultAxesColorOrder and DefaultAxesLineStyleOrder each time the plot function is called. We can customize the Default** property, which is valid until MATLAB is closed, and the Default** property will be reset to the factory setting (Factory) when Matlab is started next time.
1 2 3 set(0,'DefaultAxesColorOrder','r|g|b|k',... 'DefaultAxesLineStyleOrder','-|-.|--|:')
Use the hold all command to prevent the ColorOrder and LineStyleOrder properties from being automatically reset when the plot function is called, and instead use it in a loop. Note that hold on only overlays multiple plots (equivalent to NextPlot), but does not prevent the property from resetting.
In addition, we can set the color and size of the identifier through the following four properties
1 2 3 4 5 6 7 LineWidth-Specify Line Weight MarkerEdgeColor-Specifies the edge color of the identifier MarkerFaceColor-Specifies the identifier fill color MarkerSize-Specifies the size of the identifier
Note that the above four properties are for all curves in the current coordinate system
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 % by dynamic % see also http://www.matlabsky.com % 2009.8.20 % X=1:10; % Both are arrays and must have the same dimensions X1=[X;X;X]';%10×3 Y1=rand(10,3)+1;%10×3 % One of them is a vector and the other is an array, which automatically matches the direction of equal size X2=1:0.1:10;%1×91 Y2=[sin(X2);cos(X2)]';%91×2 % One is a scalar and the other is a vector, drawing discrete points along the vertical axis X3=1:10; Y3=-0.5; fh=figure('numbertitle','off','name','PLOT Usability Demo');%create figure object ah=axes;%create axes object h=plot(...%Returns all curve handles ah,...%Specify the coordinate system, which can be omitted, the default is at this time gca X1,Y1,...%Coordinate data '-.^',...%Curve attribute, which can be omitted or partially omitted, it is automatically selected in this case X2,Y2,... 'm-',... X3,Y3,... 'o',...%Note that setting the linetype and color for this set of data has no effect, because discrete points are drawn by default 'LineWidth',2,...%Line width 'MarkerEdgeColor','k',...%Identifier edge color 'MarkerFaceColor','r',...%Identifier fill color 'MarkerSize',8)%identifier size
subplot function analysis:
subplot is a tool for drawing multiple plots onto a single plane. Among them, m means that the figures are arranged in m rows, n means that the figures are arranged in n columns, that is, there are n figures in the whole figure are arranged in a row, a total of m rows, if the first number is 2, it means 2 rows of figures . p refers to which picture in the figure you want to draw the curve to now. If the last one is 1, it means it is the first position from left to right. Here's an example for a better understanding:
x1=[1 2 3];x2=x1;x3=x2;x4=x1;
y1=[2 4 6];y2=2*y1;y3=3*y1;y4=4*y1;
subplot(2,2,1)
plot(x1,y1);
axis([0,20,0,20])
subplot(2,2,2)
plot(x2,y2);
axis([0,20,0,20])
subplot(2,2,3)
plot(x3,y3)
axis([0,20,0,20])
subplot(2,2,4)
plot(x4,y4)
axis([0,20,0,20])
The result is:
This article is from: Analysis of the parameters of the plot function in Matlab - Erlang that Saburo - Blog Park (cnblogs.com)
Recruit a large number of matlab technicians, and there are a large number of matlab demand orders, which can be completed by individuals in a short period of time. Friends who have time can add me on WeChat: xiaoyuer-8988 Add friends to note the blog garden matlab technology. You can also contact this WeChat if you need.