Skip to content

Commit e90d859

Browse files
committed
ENH: pass at decorator which extracts a label
Not tested or used.
1 parent 5ace465 commit e90d859

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/matplotlib/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ def _replacer(data, key):
15281528
return key
15291529

15301530

1531-
def unpack_labeled_data(wl_args=None, wl_kwargs=None):
1531+
def unpack_labeled_data(wl_args=None, wl_kwargs=None, label_pos=None):
15321532
"""
15331533
A decorator to add a 'data' kwarg to any a function. The signature
15341534
of the input function must be ::
@@ -1537,6 +1537,9 @@ def foo(ax, *args, **kwargs)
15371537
15381538
so this is suitable for use with Axes methods.
15391539
"""
1540+
if label_pos is not None:
1541+
label_arg, label_kwarg = label_pos
1542+
15401543
if wl_kwargs is not None:
15411544
wl_kwargs = set(wl_kwargs)
15421545
if wl_args is not None:
@@ -1560,6 +1563,18 @@ def inner(ax, *args, **kwargs):
15601563
kwargs = dict(
15611564
(k, _replacer(data, v) if k in wl_kwargs else v)
15621565
for k, v in six.iteritems(kwargs))
1566+
if (label_pos is not None and ('label' not in kwargs or
1567+
kwargs['label'] is None)):
1568+
if len(args) > label_arg:
1569+
try:
1570+
kwargs['label'] = args[label_arg].name
1571+
except AttributeError:
1572+
pass
1573+
elif label_kwarg in kwargs:
1574+
try:
1575+
kwargs['label'] = args[label_kwarg].name
1576+
except AttributeError:
1577+
pass
15631578

15641579
return func(ax, *args, **kwargs)
15651580
return inner

0 commit comments

Comments
 (0)