Skip to content

ENH: plotting methods can unpack labeled data [MOVED TO #4829] #4787

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 8 commits into from
Closed
Prev Previous commit
Next Next commit
ENH: add white-list of args/kwargs to relpace
If white list is provided, only try to replace those.
  • Loading branch information
tacaswell committed Jul 26, 2015
commit 676eeb43c46c5909a3adc7c389dd0077e14f44bb
43 changes: 28 additions & 15 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ def _replacer(data, key):
return key


def unpack_labeled_data(func):
def unpack_labeled_data(wl_args=None, wl_kwargs=None):
"""
A decorator to add a 'data' kwarg to any a function. The signature
of the input function must be ::
Expand All @@ -1537,20 +1537,33 @@ def foo(ax, *args, **kwargs)

so this is suitable for use with Axes methods.
"""
@functools.wraps(func)
def inner(ax, *args, **kwargs):
data = kwargs.pop('data', None)
if data is not None:
if rcParams['unpack_labeled']:
args = tuple(_replacer(data, a) for a in args)
kwargs = dict((k, _replacer(data, v))
for k, v in six.iteritems(kwargs))
else:
raise ValueError("Trying to unpack labeled data, but "
"rcParams['unpack_labeled'] is False")

return func(ax, *args, **kwargs)
return inner
if wl_kwargs is not None:
wl_kwargs = set(wl_kwargs)
if wl_args is not None:
wl_args = set(wl_args)

def param(func):
@functools.wraps(func)
def inner(ax, *args, **kwargs):
data = kwargs.pop('data', None)
if data is not None:
if wl_args is None:
args = tuple(_replacer(data, a) for a in args)
else:
args = tuple(_replacer(data, a) if j in wl_args else a
for j, a in enumerate(args))

if wl_kwargs is None:
kwargs = dict((k, _replacer(data, v))
for k, v in six.iteritems(kwargs))
else:
kwargs = dict(
(k, _replacer(data, v) if k in wl_kwargs else v)
for k, v in six.iteritems(kwargs))

return func(ax, *args, **kwargs)
return inner
return param

verbose.report('matplotlib version %s' % __version__)
verbose.report('verbose.level %s' % verbose.level)
Expand Down
Loading