matlab-畫圖函式:scatter和plot
由於需要畫圖的時候會經常忘記畫圖函式的具體引數,所以給總結了一下,便於自己和大家用的時候查起來方便,不用到處查,浪費很多時間。
畫圖的時候常用的畫圖函式有scatter和plot,具體語法可以直接在MATLAB命令框裡輸入:help+空格+函式名,檢視具體的語法規則,還附帶例子的,比網上查的更清楚,也更全面。
具體的圖形的表示方法:
顏色:
'yellow' 'y',黃色
'magenta' 'm',洋紅
'cyan' 'c',青色
'red' 'r',紅色
'green' 'g',綠色
'blue' 'b',藍色
'white' 'w',白色
'black' 'k',黑色
形狀:
'o' | Circle,圓形 |
'+' | Plus sign,加號 |
'*' | Asterisk,星號 |
'.' | Point,點 |
'x' | Cross,X |
'square' or 's' | Square,方形 |
'diamond' or 'd' | Diamond,菱形 |
'^' | Upward-pointing triangle,向上的箭頭 |
'v' | Downward-pointing triangle,向下的箭頭 |
'>' | Right-pointing triangle,向右的箭頭 |
'<' | Left-pointing triangle,向左的箭頭 |
'pentagram' or 'p' | Five-pointed star (pentagram),五角星 |
'hexagram' or 'h' | Six-pointed star (hexagram),六角星 |
注意:如果是'none',則表示No markers,沒有任何標記。
scatter函式的語法:
(1)scatter(x,y):creates a scatter plot with circles at the locations specified by the vectors x and y. This type of graph is also known as a bubble plot.
(2)scatter(x,y,sz):specifies the circle sizes. To plot each circle with equal size, specify sz as a scalar. To plot each circle with a different size, specify sz as a vector with length equal to the length of x and y.
(3)scatter(x,y,sz,c):specifies the circle colors. To plot all circles with the same color, specify c as a color name or an RGB triplet. To use varying color, specify c as a vector or a three-column matrix of RGB triplets.
(4)scatter(___,'filled'):fills in the circles. Use the 'filled' option with any of the input argument combinations in the previous syntaxes.
(5)scatter(___,mkr):specifies the marker type.
(6)scatter(___,Name,Value):specifies scatter series properties using one or more Name,Value pair arguments. For example, 'LineWidth',2 sets the marker outline width to 2 points.
(7)scatter(ax,___):plots into the axes specified by ax instead of into the current axes. The option ax can precede any of the input argument combinations in the previous syntaxes.
(8)s = scatter(___):returns the scatter series object. Use s to make future modifications to the scatter series after it is created.
plot函式的語法:
(1)plot(X,Y):creates a 2-D line plot of the data in Y versus the corresponding values in X.
· If X and Y are both vectors, then they must have equal length. The plot function plots Y versus X.
· If X and Y are both matrices, then they must have equal size. The plot function plots columns of Y versus columns of X.
· If one of X or Y is a vector and the other is a matrix, then the matrix must have dimensions such that one of its dimensions equals the vector length. If the number of matrix rows equals the vector length, then the plot function plots each matrix column versus the vector. If the number of matrix columns equals the vector length, then the function plots each matrix row versus the vector. If the matrix is square, then the function plots each column versus the vector.
· If one of X or Y is a scalar and the other is either a scalar or a vector, then the plot function plots discrete points. However, to see the points you must specify a marker symbol, for example, plot(X,Y,'o').
(2)plot(X,Y,LineSpec):sets the line style, marker symbol, and color.
(3)plot(X1,Y1,...,Xn,Yn):plots multiple X, Y pairs using the same axes for all lines.
(4)plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn):sets the line style, marker type, and color for each line. You can mix X, Y, LineSpec triplets with X, Y pairs. For example, plot(X1,Y1,X2,Y2,LineSpec2,X3,Y3).
(5)plot(Y) creates a 2-D line plot of the data in Y versus the index of each value.
· If Y is a vector, then the x-axis scale ranges from 1 to length(Y).
· If Y is a matrix, then the plot function plots the columns of Y versus their row number. The x-axis scale ranges from 1 to the number of rows in Y.
· If Y is complex, then the plot function plots the imaginary part of Y versus the real part of Y, such that plot(Y) is equivalent to plot(real(Y),imag(Y)).
(6)plot(Y,LineSpec):sets the line style, marker symbol, and color.
(7) plot(___,Name,Value):specifies line properties using one or more Name,Value pair arguments. For a list of properties, see Chart Line Properties. Use this option with any of the input argument combinations in the previous syntaxes. Name,Value pair settings apply to all the lines plotted.
(8)plot(ax,___):creates the line in the axes specified by ax instead of in the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes.
(9)h = plot(___):returns a column vector of chart line objects. Use h to modify properties of a specific chart line after it is created. For a list of properties, see Chart Line Properties.
整理不易,打賞請掃二維碼,感謝您的支援!