8000 Allow both linestyle definition "accents" and dash-patterns as linest… · matplotlib/matplotlib@31b7b91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31b7b91

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

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
@@ -2134,7 +2134,7 @@ def unmasked_index_ranges(mask, compressed=True):
21342134
(':', 'dotted')]
21352135

21362136
ls_mapper = dict(_linestyles)
2137-
ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
2137+
ls_mapperr = dict([(ls[1], ls[0]) for ls in _linestyles])
21382138

21392139

21402140
def align_iterators(func, *iterables):

lib/matplotlib/collections.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,21 +488,19 @@ def set_linestyle(self, ls):
488488
try:
489489
dashd = backend_bases.GraphicsContextBase.dashd
490490
if cbook.is_string_like(ls):
491+
ls = cbook.ls_mapper.get(ls, ls)
491492
if ls in dashd:
492493
dashes = [dashd[ls]]
493-
elif ls in cbook.ls_mapper:
494-
dashes = [dashd[cbook.ls_mapper[ls]]]
495494
else:
496495
raise ValueError()
497496
elif cbook.iterable(ls):
498497
try:
499498
dashes = []
500499
for x in ls:
501500
if cbook.is_string_like(x):
501+
x = cbook.ls_mapper.get(x, x)
502502
if x in dashd:
503503
dashes.append(dashd[x])
504-
elif x in cbook.ls_mapper:
505-
dashes.append(dashd[cbook.ls_mapper[x]])
506504
else:
507505
raise ValueError()
508506
elif cbook.iterable(x) and len(x) == 2:
@@ -511,7 +509,7 @@ def set_linestyle(self, ls):
511509
raise ValueError()
512510
except ValueError:
513511
if len(ls) == 2:
514-
dashes = ls
512+
dashes = [ls]
515513
else:
516514
raise ValueError()
517515
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
@@ -951,6 +951,13 @@ def set_linestyle(self, linestyle):
951951
952952
and any drawstyle in combination with a linestyle, e.g., ``'steps--'``.
953953
"""
954+
if not is_string_like(linestyle):
955+
if len(linestyle) != 2:
956+
raise ValueError()
957+
958+
self.set_dashes(linestyle[1])
959+
self._linestyle = "--"
960+
return
954961

955962
for ds in self.drawStyleKeys: # long names are first in the list
956963
if linestyle.startswith(ds):
@@ -962,8 +969,8 @@ def set_linestyle(self, linestyle):
962969
break
963970

964971
if linestyle not in self._lineStyles:
965-
if linestyle in ls_mapper:
966-
linestyle = ls_mapper[linestyle]
972+
if linestyle in ls_mapperr:
973+
linestyle = ls_mapperr[linestyle]
967974
else:
968975
verbose.report('Unrecognized line style %s, %s' %
969976
(linestyle, type(linestyle)))

lib/matplotlib/patches.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ def set_linestyle(self, ls):
348348
"""
349349
if ls is None:
350350
ls = "solid"
351+
352+
ls = cbook.ls_mapper.get(ls, ls)
351353
self._linestyle = ls
352354

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

0 commit comments

Comments
 (0)
0