linestyleorder
Syntax
Description
linestyleorder(
sets the line style
order for the current figure. The line style order is the list of line styles MATLAB® uses for plotting multiple data series in the same axes.linestyles
)
linestyleorder(
specifies the line style cycling method. The line style cycling method controls how
MATLAB cycles through the line styles when you plot multiple data series in the axes.
Valid values are linestyles
,cyclingmethod
)"aftercolor"
, "beforecolor"
, and
"withcolor"
. If you omit the cycling method,
linestyleorder
uses "withcolor"
.
linestyleorder(
modifies the line style order of the target figure or axes instead of the current figure.
Specify the target as the first argument in any of the previous syntaxes.target
,___)
lso = linestyleorder(___)
returns the line style order
as a cell array of character vectors.
Examples
Modify Plot Line Styles
Create a matrix containing 10 columns of y-coordinates.
Y = (10:15)'- (0:9)
Y = 6×10
10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2
12 11 10 9 8 7 6 5 4 3
13 12 11 10 9 8 7 6 5 4
14 13 12 11 10 9 8 7 6 5
15 14 13 12 11 10 9 8 7 6
Plot the matrix using the default line style order, which consists of one line style (solid).
plot(Y,LineWidth=1)
Change the line style order to "mixedstyles"
.
linestyleorder("mixedstyles")
Change the line style order to "mixedmarkers"
.
linestyleorder("mixedmarkers")
Specify a custom line style order which uses different combinations of line and marker specifiers.
linestyles = ["-","-o","--d"]; linestyleorder(linestyles)
Modify Line Style Cycling Method
Create a matrix containing six columns of y-coordinates.
Y = (10:15)'- (0:5)
Y = 6×6
10 9 8 7 6 5
11 10 9 8 7 6
12 11 10 9 8 7
13 12 11 10 9 8
14 13 12 11 10 9
15 14 13 12 11 10
Plot the matrix using the default line style order, which consists of one line style (solid).
plot(Y,LineWidth=1)
Specify a custom line style order without specifying the line style cycling method. By default, linestyleorder
uses the "withcolor"
method. This method uses the next color from a predefined palette and the next line style from the linestyles
array to create each subsequent line. In this plot, the first line is at the top of the plot, and the last line is at the bottom.
linestyles = ["-","--","-o"]; linestyleorder(linestyles)
Change the palette of colors so that it contains only two colors from the gem
palette. You can see all six combinations of colors and line styles.
colors = orderedcolors("gem");
colororder(colors(1:2,:))
Change the line style cycling method to "beforecolor"
. The lines cycle through all of the line styles before cycling to the next color.
linestyleorder(linestyles,"beforecolor")
Change the line style cycling method to "aftercolor"
. The lines cycle through all of the colors before cycling to the next line style.
linestyleorder(linestyles,"aftercolor")
Specify Line Styles for Different Axes
Create a matrix containing six columns of y-coordinates.
Y = (10:15)'-(0:5)
Y = 6×6
10 9 8 7 6 5
11 10 9 8 7 6
12 11 10 9 8 7
13 12 11 10 9 8
14 13 12 11 10 9
15 14 13 12 11 10
Plot the matrix in two different axes of a tiled chart layout. Both plots look the same.
tiledlayout(2,1) ax1 = nexttile; plot(ax1,Y,LineWidth=1) ax2 = nexttile; plot(ax2,Y,LineWidth=1)
Change the line style order for all the axes in the current figure by calling the linestyleorder
function without specifying the target object. As a result, both plots use the same set of line styles.
linestyles1 = ["-","--","-o"]; linestyleorder(linestyles1)
Define a different set of line styles, and assign it to the second plot by specifying the second axes (ax2
) as the target object.
linestyles2 = ["-s","-.","->"]; linestyleorder(ax2,linestyles2)
Input Arguments
linestyles
— Line styles
"mixedstyles"
| "mixedmarkers"
| combination of line and marker specifiers
Line styles, specified as one of these values:
"mixedstyles"
— MATLAB sets the line style order to["-","--","-.",":"]
."mixedmarkers"
— MATLAB sets the line style order to["-o","-*","-^","-x","-s","-p","-d"]
.Combination of line and marker specifiers — You specify a string array or cell array of character vectors, where each element of the array is a line specifier or marker specifier from the following tables. You can combine a line and a marker specifier into a single element. For example,
["-o","--",":square"]
specifies a solid line with circle markers, a dashed line without markers, and a dotted line with square markers.
Line Specifiers
Line Style | Description | Resulting Line |
---|---|---|
"-" | Solid line |
|
"--" | Dashed line |
|
":" | Dotted line |
|
"-." | Dash-dotted line |
|
Marker Specifiers
Marker | Description | Resulting Marker |
---|---|---|
"o" | Circle |
|
"+" | Plus sign |
|
"*" | Asterisk |
|
"." | Point |
|
"x" | Cross |
|
"_" | Horizontal line |
|
"|" | Vertical line |
|
"square" | Square |
|
"diamond" | Diamond |
|
"^" | Upward-pointing triangle |
|
"v" | Downward-pointing triangle |
|
">" | Right-pointing triangle |
|
"<" | Left-pointing triangle |
|
"pentagram" | Pentagram |
|
"hexagram" | Hexagram |
|
Example: linestyleorder(["-","--","-o"])
specifies a solid line, a
dashed line, and a solid line with circle markers.
cyclingmethod
— Line style cycling method
"withcolor"
(default) | "beforecolor"
| "aftercolor"
Line style cycling method, specified as one of the values from this table. The line
style cycling method controls how MATLAB cycles through the line styles when you plot multiple lines and there are
multiple colors in the ColorOrder
property of
the axes.
The examples in this table were created using the default colors in the
ColorOrder
property and three line styles
(["-","-o","--"]
).
Value | Description | Example |
---|---|---|
"withcolor" | Cycle through the line styles with the colors of the |
|
"beforecolor" | Cycle through the line styles before the colors of the
|
|
| Cycle through the line styles after the colors of the
This is the default behavior
for most plots when you do not use the |
|
target
— Target object
figure | axes
Target object, specified as a figure or any type of axes object, such as an
Axes
, PolarAxes
, or
GeographicAxes
object. If you specify a figure, all the axes in the
figure use the new line style order.
Version History
Introduced in R2024a
See Also
Functions
Properties
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)