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