# linestyleorder

Set or query line style order

Since R2024a

## Syntax

``linestyleorder(linestyles)``
``linestyleorder(linestyles,cyclingmethod)``
``linestyleorder(target,___)``
``lso = linestyleorder(___)``

## Description

example

````linestyleorder(linestyles)` 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.```

example

````linestyleorder(linestyles,cyclingmethod)` 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 `"aftercolor"`, `"beforecolor"`, and `"withcolor"`. If you omit the cycling method, `linestyleorder` uses `"withcolor"`.```

example

````linestyleorder(target,___)` 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.```
````lso = linestyleorder(___)` returns the line style order as a cell array of character vectors.```

## Examples

collapse all

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)```

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")`

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

collapse all

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 StyleDescriptionResulting Line
`"-"`Solid line

`"--"`Dashed line

`":"`Dotted line

`"-."`Dash-dotted line

Marker Specifiers

MarkerDescriptionResulting 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.

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","--"]`).

ValueDescriptionExample
`"withcolor"`

Cycle through the line styles with the colors of the `ColorOrder`.

`"beforecolor"`

Cycle through the line styles before the colors of the `ColorOrder`.

`"aftercolor"`

Cycle through the line styles after the colors of the `ColorOrder`.

This is the default behavior for most plots when you do not use the `linestyleorder` function.

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