From de05af18851d373abd333effabf066a2ad7f153a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 6 Sep 2019 10:13:11 +0200 Subject: [PATCH] Autogenerate gca(), gci() from boilerplate.py. --- lib/matplotlib/figure.py | 15 ++++++++++- lib/matplotlib/pyplot.py | 58 +++++++++------------------------------- tools/boilerplate.py | 2 ++ 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 4e0cc02f9b05..7d28cc802ebe 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1969,8 +1969,21 @@ def sca(self, a): return a def _gci(self): + # Helper for `~matplotlib.pyplot.gci`. Do not use elsewhere. """ - Helper for :func:`~matplotlib.pyplot.gci`. Do not use elsewhere. + Get the current colorable artist. + + Specifically, returns the current `.ScalarMappable` instance (`.Image` + created by `imshow` or `figimage`, `.Collection` created by `pcolor` or + `scatter`, etc.), or *None* if no such instance has been defined. + + The current image is an attribute of the current axes, or the nearest + earlier axes in the current figure that contains an image. + + Notes + ----- + Historically, the only colorable artists were images; hence the name + ``gci`` (get current image). """ # Look first for an image in the current Axes: cax = self._axstack.current_key_axes()[1] diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 07f265447b82..282180e12073 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -332,31 +332,6 @@ def rcdefaults(): draw_all() -## Current image ## - - -def gci(): - """ - Get the current colorable artist. - - Specifically, returns the current `.ScalarMappable` instance (`.Image` - created by `imshow` or `figimage`, `.Collection` created by `pcolor` or - `scatter`, etc.), or *None* if no such instance has been defined. - - The current image is an attribute of the current axes, or the nearest - earlier axes in the current figure that contains an image. - - Notes - ----- - Historically, the only colorable artists were images; hence the name - ``gci`` (get current image). - """ - return gcf()._gci() - - -## Any Artist ## - - # (getp is simply imported) @docstring.copy(_setp) def setp(obj, *args, **kwargs): @@ -851,27 +826,6 @@ def sca(ax): raise ValueError("Axes instance argument was not found in a figure") -def gca(**kwargs): - """ - Get the current :class:`~matplotlib.axes.Axes` instance on the - current figure matching the given keyword args, or create one. - - Examples - -------- - To get the current polar axes on the current figure:: - - plt.gca(projection='polar') - - If the current axes doesn't exist, or isn't a polar one, the appropriate - axes will be created and then returned. - - See Also - -------- - matplotlib.figure.Figure.gca : The figure's gca method. - """ - return gcf().gca(**kwargs) - - ## More ways of creating axes ## @docstring.dedent_interpd @@ -2339,6 +2293,18 @@ def figtext( x, y, s, fontdict=fontdict, withdash=withdash, **kwargs) +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy(Figure.gca) +def gca(**kwargs): + return gcf().gca(**kwargs) + + +# Autogenerated by boilerplate.py. Do not edit as changes will be lost. +@docstring.copy(Figure._gci) +def gci(): + return gcf()._gci() + + # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @docstring.copy(Figure.ginput) def ginput( diff --git a/tools/boilerplate.py b/tools/boilerplate.py index caec5247410e..5bb4068a42ed 100644 --- a/tools/boilerplate.py +++ b/tools/boilerplate.py @@ -177,6 +177,8 @@ def boilerplate_gen(): _figure_commands = ( 'figimage', 'figtext:text', + 'gca', + 'gci:_gci', 'ginput', 'suptitle', 'waitforbuttonpress',