Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions galleries/examples/lines_bars_and_markers/linestyles.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
"""
.. _linestyle_def:

==========
Linestyles
==========

Simple linestyles can be defined using the strings "solid", "dotted", "dashed"
or "dashdot". More refined control can be achieved by providing a dash tuple
``(offset, (on_off_seq))``. For example, ``(0, (3, 10, 1, 15))`` means
(3pt line, 10pt space, 1pt line, 15pt space) with no offset, while
``(5, (10, 3))``, means (10pt line, 3pt space), but skip the first 5pt line.
See also `.Line2D.set_linestyle`. The specific on/off sequences of the
"dotted", "dashed" and "dashdot" styles are configurable:
Linestyles can be specified in two ways:

* **Named linestyles**: "solid", "dotted", "dashed", "dashdot" and their
short forms "-", ":", "--", "-."
* **Parametrized linestyles**: a dash tuple ``(offset, (on_off_seq))``. For example,
``(0, (3, 10, 1, 15))`` means (3pt line, 10pt space, 1pt line, 15pt space) with no
offset, while ``(5, (10, 3))``, means (10pt line, 3pt space), but skip the first
5pt line.

See also `.Line2D.set_linestyle`.

The specific on/off sequences of the "dotted", "dashed" and "dashdot" styles are
configurable:

* :rc:`lines.dotted_pattern`
* :rc:`lines.dashed_pattern`
Expand Down
9 changes: 3 additions & 6 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ def acorr(self, x, **kwargs):
Other Parameters
----------------
linestyle : `~matplotlib.lines.Line2D` property, optional
linestyle : :mpltype:`linestyle`, optional
The linestyle for plotting the data points.
Only used if *usevlines* is ``False``.
Expand Down Expand Up @@ -2078,7 +2078,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
Other Parameters
----------------
linestyle : `~matplotlib.lines.Line2D` property, optional
linestyle : :mpltype:`linestyle`, optional
The linestyle for plotting the data points.
Only used if *usevlines* is ``False``.
Expand Down Expand Up @@ -4027,11 +4027,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
The linewidth of the errorbar lines. If None, the linewidth of
the current style is used.
elinestyle : str or tuple, default: 'solid'
elinestyle : :mpltype:`linestyle`, default: 'solid'
The linestyle of the errorbar lines.
Valid values for linestyles include {'-', '--', '-.',
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
complete description.
capsize : float, default: :rc:`errorbar.capsize`
The length of the error bar caps in points.
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3608,8 +3608,8 @@ def tick_params(self, axis='both', **kwargs):
Transparency of gridlines: 0 (transparent) to 1 (opaque).
grid_linewidth : float
Width of gridlines in points.
grid_linestyle : str
Any valid `.Line2D` line style spec.
grid_linestyle : :mpltype:`linestyle`
Linestyle of the gridlines.

Examples
--------
Expand Down
12 changes: 3 additions & 9 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def set_linestyle(self, ls):

Parameters
----------
ls : {'-', '--', '-.', ':', '', ...} or (offset, on-off-seq) or list thereof
ls : :mpltype:`linestyle` or list of :mpltype:`linestyle`
If a list, the individual elements are assigned to the elements of the
collection.

Expand Down Expand Up @@ -1933,14 +1933,8 @@ def __init__(self,
The line width of the event lines, in points.
color : :mpltype:`color` or list of :mpltype:`color`, default: :rc:`lines.color`
The color of the event lines.
linestyle : str or tuple or list thereof, default: 'solid'
Valid strings are ['solid', 'dashed', 'dashdot', 'dotted',
'-', '--', '-.', ':']. Dash tuples should be of the form::

(offset, onoffseq),

where *onoffseq* is an even length tuple of on and off ink
in points.
linestyle : :mpltype:`linestyle`, default: 'solid'
The linestyle of the event lines.
antialiased : bool or list thereof, default: :rc:`lines.antialiased`
Whether to use antialiasing for drawing the lines.
**kwargs
Expand Down
35 changes: 4 additions & 31 deletions lib/matplotlib/inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,11 @@ def set_linestyle(self, ls):

Parameters
----------
ls : {'-', '--', '-.', ':', '', ...} or (offset, on-off-seq)
Possible values:
ls : :mpltype:`linestyle`
A named line style (e.g. "dashed", or short "--") or a dash tuple
``(offset, (on_off_seq))``.

- A string:

======================================================= ================
linestyle description
======================================================= ================
``'-'`` or ``'solid'`` solid line
``'--'`` or ``'dashed'`` dashed line
``'-.'`` or ``'dashdot'`` dash-dotted line
``':'`` or ``'dotted'`` dotted line
``''`` or ``'none'`` (discouraged: ``'None'``, ``' '``) draw nothing
======================================================= ================

- A tuple describing the start position and lengths of dashes and spaces:

(offset, onoffseq)

where

- *offset* is a float specifying the offset (in points); i.e. how much
is the dash pattern shifted.
- *onoffseq* is a sequence of on and off ink in points. There can be
arbitrary many pairs of on and off values.

Example: The tuple ``(0, (10, 5, 1, 5))`` means that the pattern starts
at the beginning of the line. It draws a 10 point long dash,
then a 5 point long space, then a 1 point long dash, followed by a 5 point
long space, and then the pattern repeats.

For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
For a full reference see :doc:`/gallery/lines_bars_and_markers/linestyles`.
"""
self._shared_setter('linestyle', ls)

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def set_linestyle(self, ls):

Parameters
----------
ls : {'-', '--', '-.', ':', '', ...} or (offset, on-off-seq)
ls : :mpltype:`linestyle`
Possible values:

- A string:
Expand Down
35 changes: 4 additions & 31 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,38 +510,11 @@ def set_linestyle(self, ls):

Parameters
----------
ls : {'-', '--', '-.', ':', '', ...} or (offset, on-off-seq)
Possible values:
ls : :mpltype:`linestyle`
A named line style (e.g. "dashed", or short "--") or a dash tuple
``(offset, (on_off_seq))``.

- A string:

======================================================= ================
linestyle description
======================================================= ================
``'-'`` or ``'solid'`` solid line
``'--'`` or ``'dashed'`` dashed line
``'-.'`` or ``'dashdot'`` dash-dotted line
``':'`` or ``'dotted'`` dotted line
``''`` or ``'none'`` (discouraged: ``'None'``, ``' '``) draw nothing
======================================================= ================

- A tuple describing the start position and lengths of dashes and spaces:

(offset, onoffseq)

where

- *offset* is a float specifying the offset (in points); i.e. how much
is the dash pattern shifted.
- *onoffseq* is a sequence of on and off ink in points. There can be
arbitrary many pairs of on and off values.

Example: The tuple ``(0, (10, 5, 1, 5))`` means that the pattern starts
at the beginning of the line. It draws a 10 point long dash,
then a 5 point long space, then a 1 point long dash, followed by a 5 point
long space, and then the pattern repeats.

For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
For a full reference see :doc:`/gallery/lines_bars_and_markers/linestyles`.
"""
if ls is None:
ls = "solid"
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/sphinxext/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def _mpltype_role(name, rawtext, text, lineno, inliner, options=None, content=No
type_to_link_target = {
'color': 'colors_def',
'hatch': 'hatch_def',
'linestyle': 'linestyle_def',
}
if mpltype not in type_to_link_target:
raise ValueError(f"Unknown mpltype: {mpltype!r}")
Expand Down
Loading