Skip to content

Allow both linestyle definition "accents" and dash-patterns as linestyle... #3265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Allow both linestyle definition "accents" and dash-patterns as linest…
…yle for collection, lines and patches.

(code & tests)
  • Loading branch information
lennart0901 committed Oct 19, 2014
commit 62fe186abb76f9987cdaf0389cec7a502672ccd0
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ def unmasked_index_ranges(mask, compressed=True):
(':', 'dotted')]

ls_mapper = dict(_linestyles)
ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
ls_mapperr = dict([(ls[1], ls[0]) for ls in _linestyles])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have both ls_mapper and ls_mapperr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put the mapper into one, there is no way to decide which side of the mapping is "authoritative" (useable at the end in the backend). So I decided to divide them into a forward and reverse mapper here. So the mappers can be used without checking if the passed linestyle might be ok for the backend etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use ls_mapper_r which matches our convention for color maps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to suggest that as well. Also, add a comment explaining the
reasoning you gave above.

On Tue, Jul 15, 2014 at 1:43 PM, Thomas A Caswell notifications@github.com
wrote:

In lib/matplotlib/cbook.py:

@@ -2074,7 +2074,7 @@ def unmasked_index_ranges(mask, compressed=True):
(':', 'dotted')]

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

can you use ls_mapper_r which matches our convention for color maps?


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3265/files#r14950740.



def align_iterators(func, *iterables):
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,21 +469,19 @@ def set_linestyle(self, ls):
try:
dashd = backend_bases.GraphicsContextBase.dashd
if cbook.is_string_like(ls):
ls = cbook.ls_mapper.get(ls, ls)
if ls in dashd:
dashes = [dashd[ls]]
elif ls in cbook.ls_mapper:
dashes = [dashd[cbook.ls_mapper[ls]]]
else:
raise ValueError()
elif cbook.iterable(ls):
try:
dashes = []
for x in ls:
if cbook.is_string_like(x):
x = cbook.ls_mapper.get(x, x)
if x in dashd:
dashes.append(dashd[x])
elif x in cbook.ls_mapper:
dashes.append(dashd[cbook.ls_mapper[x]])
else:
raise ValueError()
elif cbook.iterable(x) and len(x) == 2:
Expand All @@ -492,7 +490,7 @@ def set_linestyle(self, ls):
raise ValueError()
except ValueError:
if len(ls) == 2:
dashes = ls
dashes = [ls]
else:
raise ValueError()
else:
Expand Down
13 changes: 10 additions & 3 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from matplotlib import verbose
from . import artist
from .artist import Artist
from .cbook import iterable, is_string_like, is_numlike, ls_mapper
from .cbook import iterable, is_string_like, is_numlike, ls_mapperr
from .colors import colorConverter
from .path import Path
from .transforms import Bbox, TransformedPath, IdentityTransform
Expand Down Expand Up @@ -946,6 +946,13 @@ def set_linestyle(self, linestyle):

and any drawstyle in combination with a linestyle, e.g., ``'steps--'``.
"""
if not is_string_like(linestyle):
if len(linestyle) != 2:
raise ValueError()

self.set_dashes(linestyle[1])
self._linestyle = "--"
return

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

if linestyle not in self._lineStyles:
if linestyle in ls_mapper:
linestyle = ls_mapper[linestyle]
if linestyle in ls_mapperr:
linestyle = ls_mapperr[linestyle]
else:
verbose.report('Unrecognized line style %s, %s' %
(linestyle, type(linestyle)))
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ def set_linestyle(self, ls):
"""
if ls is None:
ls = "solid"

ls = cbook.ls_mapper.get(ls, ls)
self._linestyle = ls

def set_ls(self, ls):
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading