[matlab] Detailed usage of Plot

1, plot(Y)  draws a two-dimensional line graph based on Y
    plot(Y, LineSpec) draws a two-dimensional line graph based on Y, and specifies the drawing style

  •  If Y is a vector, the x-axis ranges from 1 to the value of length(Y), the length of the vector, and the y-axis ranges from the values ​​of the elements of the vector from left to right.
  • If Y is a matrix, the x-axis ranges from 1 to the maximum number of rows of the matrix, and the y-axis is the element value of the matrix columns. Each line corresponds to a column of the matrix.
  • If the matrix is ​​complex, plot(Y) is equivalent to plot(real(y), imag(Y)).

2, plot(X, Y)

    plot(X, Y, LineSpec)

    plot (X1, Y1, ..., Xn, Yn)

    plot(X1, Y1, LineSpec1, ..., Xn, Yn, LineSpecn)

  •  If both X and Y are vectors, and X and Y must be the same length, the x-axis range is the value of each element of the X vector, and the y-axis range is the value of each element of the Y vector.
  • If both X and Y are matrices, and X and Y must be the same size, plot the limits for each column of Y and each column of X.
  • If one of X and Y is a vector and the other is a matrix, and the matrix must have a latitude that is the same length as the vector.
    • If the row latitude and vector length of the matrix are the same, draw the line graph corresponding to each row and vector of the matrix;
    • If the column latitude of the matrix and the length of the vector are the same, the line graph corresponding to each column of the matrix and the vector is drawn;
    • If the matrix is ​​a square matrix, draw a line graph corresponding to each column of the matrix and the vector.
  • If one of X and Y is a scalar and the other is a scalar or a vector, then draw a scatter. But if you want to see the points, you need to specify the id, like plot(X, Y, 'o')

3, plot( ___, Name, Value)

    Use the combination of drawing property name and value to set the line width, mark size, and mark color of the line, where Name is the property name and Value is the property value. Name and Value need to be enclosed in single quotes ''. Such as plot(X, Y, 'color', 'r').
    Specific properties:

  • Line property
    LineStyle -- line style:    '-' (default) |  '--' |  ':' |  '-.' |  'none'
    LineWidth -- line width:   0.5 (default) | positive value
    Color -- color (RGB value, or color abbreviation like 'r'):   [0 0 0] (default) | RGB triplet | character vector of color name |  'none'
    LineJoin -- discounted corner shape:  'round' (default) |  'miter' |  'chamfer'
    AlignVertexCenters -- Sharp vertical and horizontal lines:  'off' (default) | 'on'
  • Markers property
    Marker -- x value: x vector value
    MarkerIndices -- Indices of data points at which to display markers
    MarkerSize -- Marker size
    MarkerEdgeColor -- edge color
    MakerFaceColor -- fill color

4, plot(ax, ___)

        Draws the image in the coordinates specified by ax instead of the current coordinates (gca).
        For example, two sub-coordinates are created in a figure, and the figures are drawn in the sub-coordinates respectively.

figure % new figure
ax1 = subplot(2,1,1); % top subplot
ax2 = subplot(2,1,2); % bottom subplot
x = linspace(0,3);
y1 = sin(5*x);
y2 = sin(15*x);

plot(ax1,x,y1)
title(ax1,'Top Subplot')
ylabel (ax1, 'sin (5x)')

plot(ax2,x,y2)
title(ax2,'Bottom Subplot')
ylabel(ax2,'sin(15x)')

 

5, LineSpec

    LineSpec is a character vector consisting of Line Style, Marker, and Color, and uses single quotes ''. Such as '--or', where -- specifies the line shape as a dashed line, o specifies the mark as a circle, and r specifies the color as red.
    Other properties are as follows:

  • Line Style:- %实线    -- %虚线    :%点线    -. %虚点线
  • Marker:o %圆圈形    + %加号形    * %星号形    . %点形   x %叉号形  s %方点形   d %钻石形  ^ %上三角形  v %下三角形  > %右三角形  < %左三角形  p %五角星形   h %六角星形
  • Color: y %黄色    m %绛红色    c %青色     r %红色    g %绿色    b %蓝色     w %白色     k %黑色

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325677802&siteId=291194637