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