Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaacb3cc

Browse files
committed
Also autogenerate isinteractive and rcdefaults.
1 parent2748d57 commitaacb3cc

File tree

3 files changed

+128
-146
lines changed

3 files changed

+128
-146
lines changed

‎lib/matplotlib/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,25 +1394,25 @@ def get_backend():
13941394

13951395
definteractive(b):
13961396
"""
1397-
Set interactive mode to booleanb.
1397+
Set interactive mode to boolean*b*.
13981398
1399-
Ifb is True, then draw after every plotting command, e.g., after xlabel
1399+
If*b* is True, then draw after every plotting command, e.g., after xlabel.
14001400
"""
14011401
rcParams['interactive']=b
14021402

14031403

14041404
defis_interactive():
1405-
'Returntrue if plotmode isinteractive'
1405+
"""Returnwhether interactivemode ison."""
14061406
returnrcParams['interactive']
14071407

14081408

14091409
deftk_window_focus():
14101410
"""Return true if focus maintenance under TkAgg on win32 is on.
1411-
This currently works only for python.exe and IPython.exe.
1412-
Both IDLE and Pythonwin.exefail badly when tk_window_focus is on."""
1413-
ifrcParams['backend']!='TkAgg':
1414-
returnFalse
1415-
returnrcParams['tk.window_focus']
1411+
1412+
This currently works only for python.exeand IPython.exe.
1413+
Both IDLE and Pythonwin.exe fail badly when tk_window_focus is on.
1414+
"""
1415+
returnrcParams['backend']=='TkAgg'andrcParams['tk.window_focus']
14161416

14171417

14181418
default_test_modules= [

‎lib/matplotlib/axes/_base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,18 +1776,19 @@ def get_yticklines(self):
17761776
# Adding and tracking artists
17771777

17781778
def_sci(self,im):
1779-
"""
1780-
helper for :func:`~matplotlib.pyplot.sci`;
1781-
do not use elsewhere.
1779+
"""Set the current image.
1780+
1781+
This image will be the target of colormap functions like
1782+
`~matplotlib.pyplot.viridis`, and other functions such as
1783+
`~matplotlib.pyplot.hot` or `~matplotlib.pyplot.clim`. The current
1784+
image is an attribute of the current axes.
17821785
"""
17831786
ifisinstance(im,matplotlib.contour.ContourSet):
17841787
ifim.collections[0]notinself.collections:
1785-
raiseValueError(
1786-
"ContourSet must be in current Axes")
1788+
raiseValueError("ContourSet must be in current Axes")
17871789
elifimnotinself.imagesandimnotinself.collections:
1788-
raiseValueError(
1789-
"Argument must be an image, collection, or ContourSet in "
1790-
"this Axes")
1790+
raiseValueError("Argument must be an image, collection, or "
1791+
"ContourSet in this Axes")
17911792
self._current_image=im
17921793

17931794
def_gci(self):

‎lib/matplotlib/pyplot.py

Lines changed: 111 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ def show(*args, **kw):
247247
return_show(*args,**kw)
248248

249249

250-
defisinteractive():
251-
"""Return status of interactive mode."""
252-
returnmatplotlib.is_interactive()
253-
254-
255250
defioff():
256251
"""Turn interactive mode off."""
257252
matplotlib.interactive(False)
@@ -290,26 +285,6 @@ def pause(interval):
290285
time.sleep(interval)
291286

292287

293-
@docstring.copy_dedent(matplotlib.rcdefaults)
294-
defrcdefaults():
295-
matplotlib.rcdefaults()
296-
ifmatplotlib.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-
defsci(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-
313288
## Any Artist ##
314289

315290

@@ -1943,111 +1918,117 @@ def getname_val(identifier):
19431918
install_repl_displayhook()
19441919

19451920

1946-
def_make_wrapper(obj_getter,cls,command):
1947-
if":"incommand:
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,lambdaobj:None)
1953-
1954-
deffunc(*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-
returnret
1960-
1961-
ifsix.PY2:
1962-
func.__name__=func_name.encode("ascii")
1963-
importfuncsigs
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":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
2007-
"contourf":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
2008-
"tricontour":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
2009-
"tricontourf":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
2010-
"hist2d":lambdaret:sci(ret[-1]),
2011-
"specgram":lambdaret:sci(ret[-1]),
2012-
"streamplot":lambdaret:sci(ret.lines),
2013-
"spy": (
2014-
lambdaret:sci(ret)ifisinstance(ret,cm.ScalarMappable)elseNone)
2015-
}
2016-
2017-
for_commandin_canvas_commands:
2018-
_make_wrapper(
2019-
lambda:get_current_fig_manager().canvas,FigureCanvasBase,_command)
2020-
for_commandin_fig_commands:
2021-
_make_wrapper(gcf,Figure,_command)
2022-
for_commandin_axes_commands:
2023-
_make_wrapper(gca,Axes,_command)
2024-
2025-
2026-
def_make_cmap_wrapper(name):
2027-
2028-
deffunc():
2029-
rc("image",cmap=name)
2030-
im=gci()
2031-
ifimisnotNone:
2032-
im.set_cmap(name)
2033-
2034-
func.__name__=name.encode("ascii")ifsix.PY2elsename
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_cmapin_cmaps:
2050-
_make_cmap_wrapper(_cmap)
1921+
def_make_wrappers(obj_getter,base,commands,post_processors):
1922+
defmake_closure(func_name,wrapper_name,post_processor):
1923+
defwrapper(*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+
returnret
1929+
1930+
func=getattr(base,func_name)
1931+
ifsix.PY2:
1932+
wrapper.__name__=wrapper_name.encode("ascii")
1933+
importfuncsigs
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+
ifisinstance(base,type)elsesig)
1944+
globals()[wrapper.__name__]=wrapper
1945+
1946+
forcommandincommands:
1947+
if":"incommand:
1948+
func_name,wrapper_name=command.split(":")
1949+
else:
1950+
func_name=wrapper_name=command
1951+
post_processor=post_processors.get(wrapper_name,lambdaobj: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()ifmatplotlib.is_interactive()elseNone})
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":lambdaret:sci(ret),
1991+
"imshow":lambdaret:sci(ret),
1992+
"pcolor":lambdaret:sci(ret),
1993+
"pcolormesh":lambdaret:sci(ret),
1994+
"quiver":lambdaret:sci(ret),
1995+
"scatter":lambdaret:sci(ret),
1996+
"tripcolor":lambdaret:sci(ret),
1997+
"contour":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
1998+
"contourf":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
1999+
"tricontour":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
2000+
"tricontourf":lambdaret:sci(ret)ifret._AisnotNoneelseNone,
2001+
"hist2d":lambdaret:sci(ret[-1]),
2002+
"specgram":lambdaret:sci(ret[-1]),
2003+
"streamplot":lambdaret:sci(ret.lines),
2004+
"spy":lambdaret: (sci(ret)ifisinstance(ret,cm.ScalarMappable)
2005+
elseNone)})
2006+
2007+
2008+
def_make_cmap_wrappers(names):
2009+
defmake_closure(name):
2010+
deffunc():
2011+
rc("image",cmap=name)
2012+
im=gci()
2013+
ifimisnotNone:
2014+
im.set_cmap(name)
2015+
2016+
func.__name__=name.encode("ascii")ifsix.PY2elsename
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+
fornameinnames:
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"])
20512032

20522033

20532034
__all__=sorted([nameforname,objinglobals().items()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp