@@ -312,26 +312,8 @@ def rcdefaults():
312
312
draw_all ()
313
313
314
314
315
- # The current "image" (ScalarMappable) is retrieved or set
316
- # only via the pyplot interface using the following two
317
- # functions:
318
- def gci ():
319
- """
320
- Get the current colorable artist. Specifically, returns the
321
- current :class:`~matplotlib.cm.ScalarMappable` instance (image or
322
- patch collection), or *None* if no images or patch collections
323
- have been defined. The commands :func:`~matplotlib.pyplot.imshow`
324
- and :func:`~matplotlib.pyplot.figimage` create
325
- :class:`~matplotlib.image.Image` instances, and the commands
326
- :func:`~matplotlib.pyplot.pcolor` and
327
- :func:`~matplotlib.pyplot.scatter` create
328
- :class:`~matplotlib.collections.Collection` instances. The
329
- current image is an attribute of the current axes, or the nearest
330
- earlier axes in the current figure that contains an image.
331
- """
332
- return gcf ()._gci ()
333
-
334
-
315
+ # This function is not autogenerated because it is needed in when
316
+ # autogenerating other functions, see `_post_processors`.
335
317
def sci (im ):
336
318
"""
337
319
Set the current image. This image will be the target of colormap
@@ -1979,23 +1961,6 @@ def getname_val(identifier):
1979
1961
fig .autofmt_xdate ()
1980
1962
1981
1963
1982
- def _autogen_docstring (base ):
1983
- """Autogenerated wrappers will get their docstring from a base function
1984
- with an addendum."""
1985
- msg = ''
1986
- addendum = docstring .Appender (msg , '\n \n ' )
1987
- return lambda func : addendum (docstring .copy_dedent (base )(func ))
1988
-
1989
-
1990
- # This function cannot be generated by boilerplate.py because it may
1991
- # return an image or a line.
1992
- @_autogen_docstring (Axes .spy )
1993
- def spy (Z , precision = 0 , marker = None , markersize = None , aspect = 'equal' , ** kwargs ):
1994
- ret = ax .spy (Z , precision , marker , markersize , aspect , ** kwargs )
1995
- if isinstance (ret , cm .ScalarMappable ):
1996
- sci (ret )
1997
- return ret
1998
-
1999
1964
# just to be safe. Interactive mode can be turned on without
2000
1965
# calling `plt.ion()` so register it again here.
2001
1966
# This is safe because multiple calls to `install_repl_displayhook`
@@ -2010,11 +1975,14 @@ def _make_wrapper(obj_getter, cls, command):
2010
1975
else :
2011
1976
method_name = func_name = command
2012
1977
method = getattr (cls , method_name )
1978
+ post_processor = _post_processors .get (func_name , lambda obj : None )
2013
1979
2014
1980
def func (* args , ** kwargs ):
2015
1981
# We actually need to refetch the method here in case it has been
2016
1982
# monkey-patched.
2017
- return getattr (obj_getter (), method_name )(* args , ** kwargs )
1983
+ ret = getattr (obj_getter (), method_name )(* args , ** kwargs )
1984
+ post_processor (ret )
1985
+ return ret
2018
1986
2019
1987
if six .PY2 :
2020
1988
func .__name__ = func_name .encode ("ascii" )
@@ -2035,7 +2003,7 @@ def func(*args, **kwargs):
2035
2003
"clf" , "figimage" , "gca" , "ginput" , "savefig" , "subplots_adjust" ,
2036
2004
"suptitle" , "tight_layout" , "waitforbuttonpress" ,
2037
2005
# Renamed commands.
2038
- "legend:figlegend" , "text:figtext" ]
2006
+ "_gci:gci" , " legend:figlegend" , "text:figtext" ]
2039
2007
_axes_commands = [
2040
2008
"acorr" , "angle_spectrum" , "annotate" , "arrow" , "autoscale" , "axhline" ,
2041
2009
"axhspan" , "axis" , "axvline" , "axvspan" , "bar" , "barbs" , "barh" , "boxplot" ,
@@ -2051,7 +2019,26 @@ def func(*args, **kwargs):
2051
2019
# Renamed commands.
2052
2020
"set_title:title" , "set_xlabel:xlabel" , "set_xscale:xscale" ,
2053
2021
"set_ylabel:ylabel" , "set_yscale:yscale" ]
2054
-
2022
+ _post_processors = {
2023
+ # For the following functions, an additional callable will be called with
2024
+ # the return value as argument.
2025
+ "hexbin" : sci ,
2026
+ "imshow" : sci ,
2027
+ "pcolor" : sci ,
2028
+ "pcolormesh" : sci ,
2029
+ "quiver" : sci ,
2030
+ "scatter" : sci ,
2031
+ "tripcolor" : sci ,
2032
+ "contour" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2033
+ "contourf" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2034
+ "tricontour" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2035
+ "tricontourf" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2036
+ "hist2d" : lambda ret : sci (ret [- 1 ]),
2037
+ "specgram" : lambda ret : sci (ret [- 1 ]),
2038
+ "streamplot" : lambda ret : sci (ret .lines ),
2039
+ "spy" : (
2040
+ lambda ret : sci (ret ) if isinstance (ret , cm .ScalarMappable ) else None )
2041
+ }
2055
2042
2056
2043
for _command in _canvas_commands :
2057
2044
_make_wrapper (
0 commit comments