Skip to content

ENH: first draft of ensure_ax decorator #4488

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 11 commits into from
Prev Previous commit
Next Next commit
ENH: add registration function
  • Loading branch information
tacaswell committed Aug 30, 2015
commit a7918be843024df85e322f48c93b8c8f17db0cfd
27 changes: 27 additions & 0 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,33 @@ def inner(*args, **kwargs):
return inner


def register_func(func):
"""
Registers a function to be wrapped and made available in the
pyplot namespace for convenient interactive command line use.
Copy link
Member

Choose a reason for hiding this comment

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

command-line use? Might be misleading. Would probably be better as just "interactive use".

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to keep something in there so we don't encourage people to use these
functions in other functions.

I am a bit hesitant to include this at all for exactly that reason.

On Tue, Jul 7, 2015, 3:06 PM Benjamin Root notifications@github.com wrote:

In lib/matplotlib/pyplot.py
#4488 (comment):

  •    else:
    
  •        ax = gca()
    
  •    return func(s, ax, _args, *_kwargs)
    
  • pre_doc = inner.doc
  • if pre_doc is None:
  •    pre_doc = ''
    
  • else:
  •    pre_doc = dedent(pre_doc)
    
  • inner.doc = _ENSURE_AX_DOC + pre_doc
  • return inner

+def register_func(func):

  • """
  • Registers a function to be wrapped and made available in the
  • pyplot namespace for convenient interactive command line use.

command-line use? Might be misleading. Would probably be better as just
"interactive use".


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


Parameters
----------
func : callable

First parameter of function must be an `Axes` object. Will
be wrapped by `ensure_ax`

Returns
-------
callable

The wrapped function.
"""
mod = sys.modules[__name__]
f_name = func.__name__
if hasattr(mod, f_name):
raise RuntimeError("Function already exists with that name")
setattr(mod, f_name, ensure_ax(func))

return getattr(mod, f_name)


@docstring.copy_dedent(Artist.findobj)
def findobj(o=None, match=None, include_self=True):
if o is None:
Expand Down