@@ -247,11 +247,6 @@ def show(*args, **kw):
247
247
return _show (* args , ** kw )
248
248
249
249
250
- def isinteractive ():
251
- """Return status of interactive mode."""
252
- return matplotlib .is_interactive ()
253
-
254
-
255
250
def ioff ():
256
251
"""Turn interactive mode off."""
257
252
matplotlib .interactive (False )
@@ -290,26 +285,6 @@ def pause(interval):
290
285
time .sleep (interval )
291
286
292
287
293
- @docstring .copy_dedent (matplotlib .rcdefaults )
294
- def rcdefaults ():
295
- matplotlib .rcdefaults ()
296
- if matplotlib .is_interactive ():
297
- draw_all ()
298
-
299
-
300
- # This function is not autogenerated because it is needed in when
301
- # autogenerating other functions, see `_post_processors`.
302
- def sci (im ):
303
- """
304
- Set the current image. This image will be the target of colormap
305
- commands like :func:`~matplotlib.pyplot.jet`,
306
- :func:`~matplotlib.pyplot.hot` or
307
- :func:`~matplotlib.pyplot.clim`). The current image is an
308
- attribute of the current axes.
309
- """
310
- gca ()._sci (im )
311
-
312
-
313
288
## Any Artist ##
314
289
315
290
@@ -1942,111 +1917,117 @@ def getname_val(identifier):
1942
1917
install_repl_displayhook ()
1943
1918
1944
1919
1945
- def _make_wrapper (obj_getter , cls , command ):
1946
- if ":" in command :
1947
- method_name , func_name = command .split (":" )
1948
- else :
1949
- method_name = func_name = command
1950
- method = getattr (cls , method_name )
1951
- post_processor = _post_processors .get (func_name , lambda obj : None )
1952
-
1953
- def func (* args , ** kwargs ):
1954
- # We actually need to refetch the method here in case it has been
1955
- # monkey-patched.
1956
- ret = getattr (obj_getter (), method_name )(* args , ** kwargs )
1957
- post_processor (ret )
1958
- return ret
1959
-
1960
- if six .PY2 :
1961
- func .__name__ = func_name .encode ("ascii" )
1962
- import funcsigs
1963
- sig = funcsigs .signature (method )
1964
- else :
1965
- func .__name__ = func_name
1966
- sig = inspect .signature (method )
1967
-
1968
- func .__doc__ = method .__doc__
1969
- func .__signature__ = sig .replace (
1970
- parameters = list (sig .parameters .values ())[1 :])
1971
- globals ()[func .__name__ ] = func
1972
-
1973
-
1974
- _canvas_commands = ["draw" , "mpl_connect:connect" , "mpl_disconnect:disconnect" ]
1975
- _fig_commands = [
1976
- "clf" , "figimage" , "gca" , "ginput" , "savefig" , "subplots_adjust" ,
1977
- "suptitle" , "tight_layout" , "waitforbuttonpress" ,
1978
- # Renamed commands.
1979
- "_gci:gci" , "legend:figlegend" , "text:figtext" ]
1980
- _axes_commands = [
1981
- "acorr" , "angle_spectrum" , "annotate" , "arrow" , "autoscale" , "axhline" ,
1982
- "axhspan" , "axis" , "axvline" , "axvspan" , "bar" , "barbs" , "barh" , "boxplot" ,
1983
- "broken_barh" , "cla" , "clabel" , "cohere" , "contour" , "contourf" , "csd" ,
1984
- "errorbar" , "eventplot" , "fill" , "fill_between" , "fill_betweenx" , "grid" ,
1985
- "hexbin" , "hist" , "hist2d" , "hlines" , "imshow" , "legend" , "locator_params" ,
1986
- "loglog" , "magnitude_spectrum" , "margins" , "minorticks_off" ,
1987
- "minorticks_on" , "pcolor" , "pcolormesh" , "phase_spectrum" , "pie" , "plot" ,
1988
- "plot_date" , "psd" , "quiver" , "quiverkey" , "scatter" , "semilogx" ,
1989
- "semilogy" , "specgram" , "stackplot" , "stem" , "step" , "streamplot" , "table" ,
1990
- "text" , "tick_params" , "ticklabel_format" , "tricontour" , "tricontourf" ,
1991
- "tripcolor" , "triplot" , "violinplot" , "vlines" , "xcorr" ,
1992
- # Renamed commands.
1993
- "set_title:title" , "set_xlabel:xlabel" , "set_xscale:xscale" ,
1994
- "set_ylabel:ylabel" , "set_yscale:yscale" ]
1995
- _post_processors = {
1996
- # For the following functions, an additional callable will be called with
1997
- # the return value as argument.
1998
- "hexbin" : sci ,
1999
- "imshow" : sci ,
2000
- "pcolor" : sci ,
2001
- "pcolormesh" : sci ,
2002
- "quiver" : sci ,
2003
- "scatter" : sci ,
2004
- "tripcolor" : sci ,
2005
- "contour" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2006
- "contourf" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2007
- "tricontour" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2008
- "tricontourf" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2009
- "hist2d" : lambda ret : sci (ret [- 1 ]),
2010
- "specgram" : lambda ret : sci (ret [- 1 ]),
2011
- "streamplot" : lambda ret : sci (ret .lines ),
2012
- "spy" : (
2013
- lambda ret : sci (ret ) if isinstance (ret , cm .ScalarMappable ) else None )
2014
- }
2015
-
2016
- for _command in _canvas_commands :
2017
- _make_wrapper (
2018
- lambda : get_current_fig_manager ().canvas , FigureCanvasBase , _command )
2019
- for _command in _fig_commands :
2020
- _make_wrapper (gcf , Figure , _command )
2021
- for _command in _axes_commands :
2022
- _make_wrapper (gca , Axes , _command )
2023
-
2024
-
2025
- def _make_cmap_wrapper (name ):
2026
-
2027
- def func ():
2028
- rc ("image" , cmap = name )
2029
- im = gci ()
2030
- if im is not None :
2031
- im .set_cmap (name )
2032
-
2033
- func .__name__ = name .encode ("ascii" ) if six .PY2 else name
2034
- func .__doc__ = """
2035
- Set the default colormap to "{}" and apply it to the current image, if any.
2036
-
2037
- See ``help(colormaps)`` for more information.
2038
- """ .format (name )
2039
- globals ()[func .__name__ ] = func
2040
-
2041
-
2042
- _cmaps = [
2043
- "autumn" , "bone" , "cool" , "copper" , "flag" , "gray" , "hot" , "hsv" ,
2044
- "inferno" , "jet" , "magma" , "nipy_spectral" , "pink" , "plasma" , "prism" ,
2045
- "spectral" , "spring" , "summer" , "viridis" , "winter" ]
2046
-
2047
-
2048
- for _cmap in _cmaps :
2049
- _make_cmap_wrapper (_cmap )
1920
+ def _make_wrappers (obj_getter , base , commands , post_processors ):
1921
+ def make_closure (func_name , wrapper_name , post_processor ):
1922
+ def wrapper (* args , ** kwargs ):
1923
+ # We actually need to refetch the func here in case it has been
1924
+ # monkey-patched.
1925
+ ret = getattr (obj_getter (), func_name )(* args , ** kwargs )
1926
+ post_processor (ret )
1927
+ return ret
1928
+
1929
+ func = getattr (base , func_name )
1930
+ if six .PY2 :
1931
+ wrapper .__name__ = wrapper_name .encode ("ascii" )
1932
+ import funcsigs
1933
+ sig = funcsigs .signature (func )
1934
+ else :
1935
+ wrapper .__name__ = wrapper_name
1936
+ sig = inspect .signature (func )
1937
+ wrapper .__doc__ = func .__doc__
1938
+ # If, and only if, the base object is a class, we are dealing with
1939
+ # methods, and the first argument gets bound.
1940
+ wrapper .__signature__ = (
1941
+ sig .replace (parameters = list (sig .parameters .values ())[1 :])
1942
+ if isinstance (base , type ) else sig )
1943
+ globals ()[wrapper .__name__ ] = wrapper
1944
+
1945
+ for command in commands :
1946
+ if ":" in command :
1947
+ func_name , wrapper_name = command .split (":" )
1948
+ else :
1949
+ func_name = wrapper_name = command
1950
+ post_processor = post_processors .get (wrapper_name , lambda obj : None )
1951
+ make_closure (func_name , wrapper_name , post_processor )
1952
+
1953
+
1954
+ _make_wrappers (
1955
+ lambda : matplotlib , matplotlib ,
1956
+ ["is_interactive:isinteractive" , "rcdefaults" ],
1957
+ {"rcdefaults" :
1958
+ lambda _ : draw_all () if matplotlib .is_interactive () else None })
1959
+ _make_wrappers (
1960
+ lambda : get_current_fig_manager ().canvas , FigureCanvasBase ,
1961
+ ["draw" , "mpl_connect:connect" , "mpl_disconnect:disconnect" ],
1962
+ {})
1963
+ _make_wrappers (
1964
+ gcf , Figure ,
1965
+ ["clf" , "figimage" , "gca" , "ginput" , "savefig" , "subplots_adjust" ,
1966
+ "suptitle" , "tight_layout" , "waitforbuttonpress" ,
1967
+ # Renamed commands.
1968
+ "_gci:gci" , "legend:figlegend" , "text:figtext" ],
1969
+ {})
1970
+ _make_wrappers (
1971
+ gca , Axes ,
1972
+ ["acorr" , "angle_spectrum" , "annotate" , "arrow" , "autoscale" , "axhline" ,
1973
+ "axhspan" , "axis" , "axvline" , "axvspan" , "bar" , "barbs" , "barh" ,
1974
+ "boxplot" , "broken_barh" , "cla" , "clabel" , "cohere" , "contour" ,
1975
+ "contourf" , "csd" , "errorbar" , "eventplot" , "fill" , "fill_between" ,
1976
+ "fill_betweenx" , "grid" , "hexbin" , "hist" , "hist2d" , "hlines" , "imshow" ,
1977
+ "legend" , "locator_params" , "loglog" , "magnitude_spectrum" , "margins" ,
1978
+ "minorticks_off" , "minorticks_on" , "pcolor" , "pcolormesh" ,
1979
+ "phase_spectrum" , "pie" , "plot" , "plot_date" , "psd" , "quiver" ,
1980
+ "quiverkey" , "scatter" , "semilogx" , "semilogy" , "specgram" , "stackplot" ,
1981
+ "stem" , "step" , "streamplot" , "table" , "text" , "tick_params" ,
1982
+ "ticklabel_format" , "tricontour" , "tricontourf" , "tripcolor" , "triplot" ,
1983
+ "violinplot" , "vlines" , "xcorr" ,
1984
+ # Renamed commands.
1985
+ "_sci:sci" , "set_title:title" , "set_xlabel:xlabel" , "set_xscale:xscale" ,
1986
+ "set_ylabel:ylabel" , "set_yscale:yscale" ],
1987
+ { # For the following functions, an additional callable will be called
1988
+ # with the return value as argument.
1989
+ "hexbin" : lambda ret : sci (ret ),
1990
+ "imshow" : lambda ret : sci (ret ),
1991
+ "pcolor" : lambda ret : sci (ret ),
1992
+ "pcolormesh" : lambda ret : sci (ret ),
1993
+ "quiver" : lambda ret : sci (ret ),
1994
+ "scatter" : lambda ret : sci (ret ),
1995
+ "tripcolor" : lambda ret : sci (ret ),
1996
+ "contour" : lambda ret : sci (ret ) if ret ._A is not None else None ,
1997
+ "contourf" : lambda ret : sci (ret ) if ret ._A is not None else None ,
1998
+ "tricontour" : lambda ret : sci (ret ) if ret ._A is not None else None ,
1999
+ "tricontourf" : lambda ret : sci (ret ) if ret ._A is not None else None ,
2000
+ "hist2d" : lambda ret : sci (ret [- 1 ]),
2001
+ "specgram" : lambda ret : sci (ret [- 1 ]),
2002
+ "streamplot" : lambda ret : sci (ret .lines ),
2003
+ "spy" : lambda ret : (sci (ret ) if isinstance (ret , cm .ScalarMappable )
2004
+ else None )})
2005
+
2006
+
2007
+ def _make_cmap_wrappers (names ):
2008
+ def make_closure (name ):
2009
+ def func ():
2010
+ rc ("image" , cmap = name )
2011
+ im = gci ()
2012
+ if im is not None :
2013
+ im .set_cmap (name )
2014
+
2015
+ func .__name__ = name .encode ("ascii" ) if six .PY2 else name
2016
+ func .__doc__ = """
2017
+ Set the default and current image's colormap to "{}".
2018
+
2019
+ See ``help(colormaps)`` for more information.
2020
+ """ .format (name )
2021
+ globals ()[func .__name__ ] = func
2022
+
2023
+ for name in names :
2024
+ make_closure (name )
2025
+
2026
+
2027
+ _make_cmap_wrappers (
2028
+ ["autumn" , "bone" , "cool" , "copper" , "flag" , "gray" , "hot" , "hsv" ,
2029
+ "inferno" , "jet" , "magma" , "nipy_spectral" , "pink" , "plasma" , "prism" ,
2030
+ "spectral" , "spring" , "summer" , "viridis" , "winter" ])
2050
2031
2051
2032
2052
2033
__all__ = sorted ([name for name , obj in globals ().items ()
0 commit comments