From ae751f48a302d0ca0439c7d047a7ad234e057472 Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Wed, 28 Jan 2026 21:48:27 +0100 Subject: [PATCH 1/7] Update handling of linestyles as tuples or strings --- lib/matplotlib/lines.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 7c374843b5c1..e72c9d8adcf0 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -45,12 +45,16 @@ def _get_dash_pattern(style): dashes = tuple(mpl.rcParams[f'lines.{style}_pattern']) # elif isinstance(style, tuple): - offset, dashes = style + if isinstance(style[1], tuple): + 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) @@ -1343,8 +1347,13 @@ def set_dashes(self, seq): """ 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.""" From bcd3251c5b4b695d9ab056e395ed6c7cae8866ad Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Wed, 28 Jan 2026 22:11:59 +0100 Subject: [PATCH 2/7] Linting --- lib/matplotlib/lines.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index e72c9d8adcf0..3af24070d260 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -43,7 +43,6 @@ 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): if isinstance(style[1], tuple): offset, dashes = style @@ -54,7 +53,6 @@ def _get_dash_pattern(style): 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) From 4b47f2c07e6555bba020903fb6efb32a07b93166 Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Fri, 30 Jan 2026 07:39:18 +0100 Subject: [PATCH 3/7] Catch (0, None) dash pattern --- lib/matplotlib/lines.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 3af24070d260..971d47fad85e 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -32,6 +32,7 @@ def _get_dash_pattern(style): """Convert linestyle to dash pattern.""" + print(style) # go from short hand -> full strings if isinstance(style, str): style = ls_mapper.get(style, style) @@ -44,7 +45,7 @@ def _get_dash_pattern(style): offset = 0 dashes = tuple(mpl.rcParams[f'lines.{style}_pattern']) elif isinstance(style, tuple): - if isinstance(style[1], tuple): + if isinstance(style[1], tuple) or style[1] is None: offset, dashes = style else: offset = 0 From 77b1afd489e141ae87711e76b94edd71aec12c3b Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Fri, 30 Jan 2026 07:50:54 +0100 Subject: [PATCH 4/7] Deal with on,off seq == None --- lib/matplotlib/lines.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 971d47fad85e..bb6585ba3892 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -32,7 +32,6 @@ def _get_dash_pattern(style): """Convert linestyle to dash pattern.""" - print(style) # go from short hand -> full strings if isinstance(style, str): style = ls_mapper.get(style, style) @@ -45,7 +44,7 @@ def _get_dash_pattern(style): offset = 0 dashes = tuple(mpl.rcParams[f'lines.{style}_pattern']) elif isinstance(style, tuple): - if isinstance(style[1], tuple) or style[1] is None: + if isinstance(style[1], (tuple,list)) or style[1] is None: offset, dashes = style else: offset = 0 @@ -55,6 +54,7 @@ def _get_dash_pattern(style): else: raise ValueError(f'Unrecognized linestyle: {style!r}') # normalize offset to be positive and shorter than the dash cycle + print(style, offset, dashes) if dashes is not None: dsum = sum(dashes) if dsum: From a701f75e133568632b3b47f52ea887355a8f48b6 Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Fri, 30 Jan 2026 08:10:28 +0100 Subject: [PATCH 5/7] Update Docstring --- lib/matplotlib/lines.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index bb6585ba3892..db407e887528 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -1329,20 +1329,36 @@ 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. - For example, (5, 2, 1, 2) describes a sequence of 5 point and 1 point - dashes separated by 2 point spaces. + If `seq` is a string, it is interpreted as a standard linestyle + specification and passed directly to `~.Line2D.set_linestyle`. + + If `seq` is a sequence of floats of even length, 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. + + If `seq` is a tuple 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('-') From 443043a9ac38c73ed95cb7e82578eaafe232e7ec Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Fri, 30 Jan 2026 08:23:37 +0100 Subject: [PATCH 6/7] Remove print statement used during debugging --- lib/matplotlib/lines.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index db407e887528..55619af4b649 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -54,7 +54,6 @@ def _get_dash_pattern(style): else: raise ValueError(f'Unrecognized linestyle: {style!r}') # normalize offset to be positive and shorter than the dash cycle - print(style, offset, dashes) if dashes is not None: dsum = sum(dashes) if dsum: @@ -1340,7 +1339,7 @@ def set_dashes(self, seq): corresponds to a 5-point dash, 2-point space, 1-point dash, and 2-point space. - If `seq` is a tuple whose second element is a sequence, it is + If `seq` is a tuple whose second element is a sequenceg, 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)``. From caa1b08855b0cd2599306038da2f8e6dd33fbbd7 Mon Sep 17 00:00:00 2001 From: Andreas Maeder Date: Sun, 1 Feb 2026 19:37:11 +0100 Subject: [PATCH 7/7] Fix docstring to pass test --- lib/matplotlib/lines.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 55619af4b649..404351bd048b 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -1331,15 +1331,15 @@ def set_dashes(self, seq): This method accepts several forms of dash specifications and forwards them to `~.Line2D.set_linestyle` as appropriate. - If `seq` is a string, it is interpreted as a standard linestyle + If a string is passed, it is interpreted as a standard linestyle specification and passed directly to `~.Line2D.set_linestyle`. - If `seq` is a sequence of floats of even length, it describes the + 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. - If `seq` is a tuple whose second element is a sequenceg, it is + 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)``.