Hướng dẫn dùng yline matlab python
ylineHorizontal line with constant y-value Show
SyntaxDescriptionexample
example
example
example
example
Examplescollapse all Create Horizontal LineCreate a horizontal line at y = 2.5. Add a LabelTo create a line with a label, you must also specify the line style. The default line style is a solid line, fplot(@(x) log(x)); xlim([0 15]); ylim([0 4]); yline(3,'-','Threshold'); Create Multiple Lines with LabelsDefine a set of x = 0:0.1:60;
y = 4.*cos(x)./(x+2);
plot(x,y)
ylim padded Find the maximum and minimum values of ymax = max(y); ymin = min(y); yline([ymax ymin],'--',{'Max','Min'})
Specify Line Style and ColorCreate a blue dash-dot line at y = 4. Specify Line Style, Thickness, and Label AlignmentCreate a horizontal dashed line with a label and a specified line width. x = -2:0.25:2; [X,Y] = meshgrid(x); Z = X.*exp(-X.^2-Y.^2); contour(X,Y,Z,30) yl = yline(0,'--','y = 0','LineWidth',3); Change the horizontal alignment of the label and the color of the line. yl.LabelHorizontalAlignment = 'center';
yl.Color = [.80 0 .40]; Add Line to Specific AxesCall the tiledlayout(1,2) ax1 = nexttile; x = -pi/2:pi/60:pi/2; y1 = tan(sin(x)) + cos(sin(x)); plot(ax1,x,y1) ax2 = nexttile; x = -pi/2:pi/60:pi/2; y2 = tan(cos(x)) + exp(x); plot(ax2,x,y2) yline(ax1,1.0); Input Argumentscollapse all y — y-coordinates scalar | vectory-coordinates, specified as a scalar or a vector containing numeric, categorical, datetime, or duration values. The data type of Example: Example: Data Types:
LineSpec — Line style and color character vector | string scalarLine style and color, specified as a character
vector or string scalar containing characters and symbols. The characters and symbols can appear in any order. You can specify the line style, line color, or both. Marker symbols such as Example:
ax — Target axes current axes (default) | Axes objectTarget axes, specified as an labels — Line labels '' (default) | character vector | string scalar | cell array of character vectors | string arrayLine labels, specified as a character vector, cell array of character vectors, string array, or numeric array. To create a multiline label, use a string array or a cell array of character vectors. Create a Label for One LineSpecify a character vector or a string scalar to display one line of text. To display multiple lines of text, specify a cell array of character vectors or a string array.
Create Labels for Multiple LinesSpecify a character vector or a string scalar to display the same label next to all the lines. Specify a cell array of character vectors or a string array to display different labels for each line.
Name-Value ArgumentsSpecify optional pairs of arguments as Before R2021a, use commas to separate each name and value, and enclose Example:
Color — Line color [0.15 0.15 0.15] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ...Line color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. For a custom color, specify an RGB triplet or a hexadecimal color code.
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.
Example: Example: Example: LineWidth — Line width 0.5 (default) | positive valueLine width, specified as a positive value in points. Legend label, specified as a character vector or string scalar. The
legend does not display until you call the LabelHorizontalAlignment — Horizontal alignment of label 'right' (default) | 'left' | 'center'Horizontal alignment of the label with respect to the line, specified as one of the options in the table.
LabelVerticalAlignment — Vertical alignment of label 'top' (default) | 'middle' | 'bottom'Vertical alignment of the label with respect to the line, specified as one of the options in the table.
LabelOrientation — Label orientation 'aligned' (default) | 'horizontal'Label orientation, specified as
AlgorithmsIn a 3-D view of the axes, the constant line appears in the x-y plane at the midpoint of the z-axis limits. If the axes are rotated, then the constant line rotates accordingly. Version HistoryIntroduced in R2018b |