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