Skip to content
Open
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
47 changes: 35 additions & 12 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ def _get_dash_pattern(style):
elif style in ['dashed', 'dashdot', 'dotted']:
offset = 0
dashes = tuple(mpl.rcParams[f'lines.{style}_pattern'])
#
elif isinstance(style, tuple):
offset, dashes = style
if isinstance(style[1], (tuple,list)) or style[1] is None:
offset, dashes = style
else:
offset = 0
dashes = style
if offset is None:
raise ValueError(f'Unrecognized linestyle: {style!r}')
else:
raise ValueError(f'Unrecognized linestyle: {style!r}')

# normalize offset to be positive and shorter than the dash cycle
if dashes is not None:
dsum = sum(dashes)
Expand Down Expand Up @@ -1326,25 +1328,46 @@ def set_dashes(self, seq):
"""
Set the dash sequence.

The dash sequence is a sequence of floats of even length describing
the length of dashes and spaces in points.
This method accepts several forms of dash specifications and forwards
them to `~.Line2D.set_linestyle` as appropriate.

If a string is passed, it is interpreted as a standard linestyle
specification and passed directly to `~.Line2D.set_linestyle`.

If a sequence of floats of even length is passed, it describes the
lengths of dashes and spaces in points. For example, ``(5, 2, 1, 2)``
corresponds to a 5-point dash, 2-point space, 1-point dash, and
2-point space.

For example, (5, 2, 1, 2) describes a sequence of 5 point and 1 point
dashes separated by 2 point spaces.
If a tuple is passed, whose second element is a sequence, it is
interpreted as a full dash specification of the form
``(offset, (on_off_ink))``. Otherwise, a tuple is treated as a raw dash
sequence and wrapped as ``(0, seq)``.

See also `~.Line2D.set_gapcolor`, which allows those spaces to be
filled with a color.

Parameters
----------
seq : sequence of floats (on/off ink in points) or (None, None)
If *seq* is empty or ``(None, None)``, the linestyle will be set
to solid.
seq : sequence of floats, tuple, or str
The dash specification. May be:

- A sequence of floats (on/off ink in points).
- A tuple ``(offset, (on_off_ink))``.
- A raw tuple of floats, which is wrapped as ``(0, seq)``.
- A string linestyle specification.
- An empty sequence or ``(None, None)``, which results in a solid
linestyle.
"""
if seq == (None, None) or len(seq) == 0:
self.set_linestyle('-')
else:
self.set_linestyle((0, seq))
elif isinstance(seq, str):
self.set_linestyle(seq)
elif isinstance(seq, tuple):
if isinstance(seq[1], tuple):
self.set_linestyle(seq)
else:
self.set_linestyle((0, seq))

def update_from(self, other):
"""Copy properties from *other* to self."""
Expand Down
Loading