8000 MNT: unify code path of set, update, setp by tacaswell · Pull Request #5599 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MNT: unify code path of set, update, setp #5599

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

Merged
merged 7 commits into from
Dec 14, 2015
Merged
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
Prev Previous commit
Next Next commit
ENH: add property precedence
Add the ability to set the precedence of properties when updating
multiple properties on once.

This adds a class-level attribute `Artist._prop_order` which is a
dictionary keyed on property names with integer values.  When using
`set` or `setp` the properties will be applied in descending order by
value then by name.
  • Loading branch information
tacaswell committed Dec 1, 2015
commit 790d9093d667f0f100b73954d6ada552479b7863
13 changes: 11 additions & 2 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class Artist(object):

aname = 'Artist'
zorder = 0
# order of precedence when bulk setting/updating properties
# via update. The keys should be property names and the values
# integers
_prop_order = dict(color=-1)

def __init__(self):
self._stale = True
Expand Down Expand Up @@ -942,7 +946,11 @@ def properties(self):
def set(self, **kwargs):
"""A property batch setter. Pass *kwargs* to set properties.
"""
return self.update(kwargs)
props = OrderedDict(
sorted(kwargs.items(), reverse=True,
key=lambda x: (self._prop_order.get(x[0], 0), x[0])))

return self.update(props)

def findobj(self, match=None, include_self=True):
"""
Expand Down Expand Up @@ -1461,8 +1469,9 @@ def setp(obj, *args, **kwargs):
funcvals = OrderedDict()
for i in range(0, len(args) - 1, 2):
funcvals[args[i]] = args[i + 1]

ret = [o.update(funcvals) for o in objs]
ret.extend([o.update(kwargs) for o in objs])
ret.extend([o.set(**kwargs) for o in objs])
return [x for x in cbook.flatten(ret)]


Expand Down
0