Skip to content

Commit 73f553e

Browse files
committed
Allow both linestyle definition "accents" and dash-patterns as linestyle for collection, lines and patches.
(code & tests)
1 parent 16b7958 commit 73f553e

File tree

10 files changed

+416
-12
lines changed

10 files changed

+416
-12
lines changed

lib/matplotlib/cbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ def unmasked_index_ranges(mask, compressed=True):
21082108
(':', 'dotted')]
21092109

21102110
ls_mapper = dict(_linestyles)
2111-
ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
2111+
ls_mapperr = dict([(ls[1], ls[0]) for ls in _linestyles])
21122112

21132113

21142114
def align_iterators(func, *iterables):

lib/matplotlib/collections.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,21 +469,19 @@ def set_linestyle(self, ls):
469469
try:
470470
dashd = backend_bases.GraphicsContextBase.dashd
471471
if cbook.is_string_like(ls):
472+
ls = cbook.ls_mapper.get(ls, ls)
472473
if ls in dashd:
473474
dashes = [dashd[ls]]
474-
elif ls in cbook.ls_mapper:
475-
dashes = [dashd[cbook.ls_mapper[ls]]]
476475
else:
477476
raise ValueError()
478477
elif cbook.iterable(ls):
479478
try:
480479
dashes = []
481480
for x in ls:
482481
if cbook.is_string_like(x):
482+
x = cbook.ls_mapper.get(x, x)
483483
if x in dashd:
484484
dashes.append(dashd[x])
485-
elif x in cbook.ls_mapper:
486-
dashes.append(dashd[cbook.ls_mapper[x]])
487485
else:
488486
raise ValueError()
489487
elif cbook.iterable(x) and len(x) == 2:
@@ -492,7 +490,7 @@ def set_linestyle(self, ls):
492490
raise ValueError()
493491
except ValueError:
494492
if len(ls) == 2:
495-
dashes = ls
493+
dashes = [ls]
496494
else:
497495
raise ValueError()
498496
else:

lib/matplotlib/lines.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from matplotlib import verbose
1717
from . import artist
1818
from .artist import Artist
19-
from .cbook import iterable, is_string_like, is_numlike, ls_mapper
19+
from .cbook import iterable, is_string_like, is_numlike, ls_mapperr
2020
from .colors import colorConverter
2121
from .path import Path
2222
from .transforms import Bbox, TransformedPath, IdentityTransform
@@ -946,6 +946,13 @@ def set_linestyle(self, linestyle):
946946
947947
and any drawstyle in combination with a linestyle, e.g., ``'steps--'``.
948948
"""
949+
if not is_string_like(linestyle):
950+
if len(linestyle) != 2:
951+
raise ValueError()
952+
953+
self.set_dashes(linestyle[1])
954+
self._linestyle = "--"
955+
return
949956

950957
for ds in self.drawStyleKeys: # long names are first in the list
951958
if linestyle.startswith(ds):
@@ -957,8 +964,8 @@ def set_linestyle(self, linestyle):
957964
break
958965

959966
if linestyle not in self._lineStyles:
960-
if linestyle in ls_mapper:
961-
linestyle = ls_mapper[linestyle]
967+
if linestyle in ls_mapperr:
968+
linestyle = ls_mapperr[linestyle]
962969
else:
963970
verbose.report('Unrecognized line style %s, %s' %
964971
(linestyle, type(linestyle)))

lib/matplotlib/patches.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ def set_linestyle(self, ls):
343343
"""
344344
if ls is None:
345345
ls = "solid"
346+
347+
ls = cbook.ls_mapper.get(ls, ls)
346348
self._linestyle = ls
347349

348350
def set_ls(self, ls):
Binary file not shown.

0 commit comments

Comments
 (0)