Skip to content

Commit a7918be

Browse files
committed
ENH: add registration function
1 parent ffdbe6e commit a7918be

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/matplotlib/pyplot.py

+27
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,33 @@ def inner(*args, **kwargs):
261261
return inner
262262

263263

264+
def register_func(func):
265+
"""
266+
Registers a function to be wrapped and made available in the
267+
pyplot namespace for convenient interactive command line use.
268+
269+
Parameters
270+
----------
271+
func : callable
272+
273+
First parameter of function must be an `Axes` object. Will
274+
be wrapped by `ensure_ax`
275+
276+
Returns
277+
-------
278+
callable
279+
280+
The wrapped function.
281+
"""
282+
mod = sys.modules[__name__]
283+
f_name = func.__name__
284+
if hasattr(mod, f_name):
285+
raise RuntimeError("Function already exists with that name")
286+
setattr(mod, f_name, ensure_ax(func))
287+
288+
return getattr(mod, f_name)
289+
290+
264291
@docstring.copy_dedent(Artist.findobj)
265292
def findobj(o=None, match=None, include_self=True):
266293
if o is None:

0 commit comments

Comments
 (0)