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

Commit475bc46

Browse files
committed
pep8-ify pyplot.
1 parent2f7aae4 commit475bc46

File tree

2 files changed

+53
-63
lines changed

2 files changed

+53
-63
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
MaxNLocator
6565
frommatplotlib.backendsimportpylab_setup
6666

67+
6768
## Backend detection ##
69+
6870
def_backend_selection():
6971
""" If rcParams['backend_fallback'] is true, check to see if the
7072
current backend is compatible with the current running event
@@ -74,7 +76,7 @@ def _backend_selection():
7476
ifnotrcParams['backend_fallback']orbackendnotin_interactive_bk:
7577
return
7678
is_agg_backend=rcParams['backend'].endswith('Agg')
77-
if'wx'insys.modulesandnotbackendin ('WX','WXAgg'):
79+
if'wx'insys.modulesandbackendnotin ('WX','WXAgg'):
7880
importwx
7981
ifwx.App.IsMainLoopRunning():
8082
rcParams['backend']='wx'+'Agg'*is_agg_backend
@@ -224,7 +226,8 @@ def switch_backend(newbackend):
224226
global_backend_mod,new_figure_manager,draw_if_interactive,_show
225227
matplotlib.use(newbackend,warn=False,force=True)
226228
frommatplotlib.backendsimportpylab_setup
227-
_backend_mod,new_figure_manager,draw_if_interactive,_show=pylab_setup()
229+
_backend_mod,new_figure_manager,draw_if_interactive,_show= \
230+
pylab_setup()
228231

229232

230233
defshow(*args,**kw):
@@ -284,10 +287,8 @@ def pause(interval):
284287
else:
285288
time.sleep(interval)
286289

287-
288290
## Any Artist ##
289291

290-
291292
defxkcd(scale=1,length=100,randomness=2):
292293
"""
293294
Turns on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
@@ -360,7 +361,6 @@ def __enter__(self):
360361

361362
returndummy_ctx()
362363

363-
364364
## Figures ##
365365

366366
deffigure(num=None,# autoincrement if None, else integer from 1-N
@@ -604,10 +604,8 @@ def close(*args):
604604
else:
605605
raiseTypeError('close takes 0 or 1 arguments')
606606

607-
608607
## Axes ##
609608

610-
611609
defaxes(arg=None,**kwargs):
612610
"""
613611
Add an axes to the current figure and make it the current axes.
@@ -736,12 +734,13 @@ def subplot(*args, **kwargs):
736734
import matplotlib.pyplot as plt
737735
# plot a line, implicitly creating a subplot(111)
738736
plt.plot([1,2,3])
739-
# now create a subplot which represents the top plot of a grid
740-
#with2 rows and 1 column. Since this subplot will overlap the
741-
#first, theplot (and its axes) previously created, will be removed
737+
# now create a subplot which represents the top plot of a grid with
738+
# 2 rows and 1 column. Since this subplot will overlap the first, the
739+
# plot (and its axes) previously created, will be removed
742740
plt.subplot(211)
743741
plt.plot(range(12))
744-
plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background
742+
# create a second subplot with yellow background
743+
plt.subplot(212, facecolor='y')
745744
746745
If you do not want this behavior, use the
747746
:meth:`~matplotlib.figure.Figure.add_subplot` method or the
@@ -778,28 +777,26 @@ def subplot(*args, **kwargs):
778777
779778
"""
780779
# if subplot called without arguments, create subplot(1,1,1)
781-
iflen(args)==0:
782-
args=(1,1,1)
780+
iflen(args)==0:
781+
args=(1,1,1)
783782

784783
# This check was added because it is very easy to type
785784
# subplot(1, 2, False) when subplots(1, 2, False) was intended
786785
# (sharex=False, that is). In most cases, no error will
787786
# ever occur, but mysterious behavior can result because what was
788787
# intended to be the sharex argument is instead treated as a
789788
# subplot index for subplot()
790-
iflen(args)>=3andisinstance(args[2],bool):
791-
warnings.warn("The subplot index argument to subplot() appears"
792-
"to be a boolean. Did you intend to use subplots()?")
789+
iflen(args)>=3andisinstance(args[2],bool):
790+
warnings.warn("The subplot index argument to subplot() appears"
791+
"to be a boolean. Did you intend to use subplots()?")
793792

794793
fig=gcf()
795794
a=fig.add_subplot(*args,**kwargs)
796795
bbox=a.bbox
797-
byebye= []
798-
forotherinfig.axes:
799-
ifother==a:continue
800-
ifbbox.fully_overlaps(other.bbox):
801-
byebye.append(other)
802-
foraxinbyebye:delaxes(ax)
796+
byebye= [otherforotherinfig.axes
797+
ifotherisnotaandbbox.fully_overlaps(other.bbox)]
798+
foraxinbyebye:
799+
delaxes(ax)
803800

804801
returna
805802

@@ -1021,24 +1018,28 @@ def subplot_tool(targetfig=None):
10211018
"""
10221019
Launch a subplot tool window for a figure.
10231020
1024-
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
1021+
Returns
1022+
-------
1023+
`matplotlib.widgets.SubplotTool`
10251024
"""
1026-
tbar=rcParams['toolbar']# turn off thenavigation toolbar for the toolfig
1027-
rcParams['toolbar']='None'
1025+
tbar=rcParams["toolbar"]# Turn off thenav toolbar for the toolfig.
1026+
rcParams["toolbar"]="None"
10281027
iftargetfigisNone:
10291028
manager=get_current_fig_manager()
10301029
targetfig=manager.canvas.figure
10311030
else:
1032-
#find the manager for this figure
1031+
#Find the manager for this figure.
10331032
formanagerin_pylab_helpers.Gcf._activeQue:
1034-
ifmanager.canvas.figure==targetfig:break
1035-
else:raiseRuntimeError('Could not find manager for targetfig')
1033+
ifmanager.canvas.figure==targetfig:
1034+
break
1035+
else:
1036+
raiseRuntimeError("Could not find manager for targetfig")
10361037

1037-
toolfig=figure(figsize=(6,3))
1038+
toolfig=figure(figsize=(6,3))
10381039
toolfig.subplots_adjust(top=0.9)
1039-
ret=SubplotTool(targetfig,toolfig)
1040-
rcParams['toolbar']=tbar
1041-
_pylab_helpers.Gcf.set_active(manager)#restore the current figure
1040+
ret=SubplotTool(targetfig,toolfig)
1041+
rcParams["toolbar"]=tbar
1042+
_pylab_helpers.Gcf.set_active(manager)#Restore the current figure.
10421043
returnret
10431044

10441045

@@ -1057,10 +1058,8 @@ def box(on=None):
10571058
on=notax.get_frame_on()
10581059
ax.set_frame_on(on)
10591060

1060-
10611061
## Axis ##
10621062

1063-
10641063
defxlim(*args,**kwargs):
10651064
"""
10661065
Get or set the *x* limits of the current axes.
@@ -1225,15 +1224,14 @@ def rgrids(*args, **kwargs):
12251224
"""
12261225
ax=gca()
12271226
ifnotisinstance(ax,PolarAxes):
1228-
raiseRuntimeError('rgrids only defined for polar axes')
1229-
iflen(args)==0:
1227+
raiseRuntimeError("rgrids only defined for polar axes")
1228+
iflen(args)==0:
12301229
lines=ax.yaxis.get_gridlines()
12311230
labels=ax.yaxis.get_ticklabels()
12321231
else:
12331232
lines,labels=ax.set_rgrids(*args,**kwargs)
1234-
1235-
return (silent_list('Line2D rgridline',lines),
1236-
silent_list('Text rgridlabel',labels) )
1233+
return (silent_list("Line2D rgridline",lines),
1234+
silent_list("Text rgridlabel",labels))
12371235

12381236

12391237
defthetagrids(*args,**kwargs):
@@ -1271,31 +1269,27 @@ def thetagrids(*args, **kwargs):
12711269
12721270
- *labels* are :class:`~matplotlib.text.Text` instances.
12731271
1274-
Note that on input, the *labels* argument is a list of strings,
1275-
and on output it is a list of :class:`~matplotlib.text.Text`
1276-
instances.
1272+
Note that on input, the *labels* argument is a list of strings, and on
1273+
output it is a list of :class:`~matplotlib.text.Text` instances.
12771274
12781275
Examples::
12791276
12801277
# set the locations of the radial gridlines and labels
1281-
lines, labels = thetagrids(range(45,360,90))
1278+
lines, labels = thetagrids(range(45,360,90))
12821279
12831280
# set the locations and labels of the radial gridlines and labels
1284-
lines, labels = thetagrids(range(45,360,90), ('NE', 'NW', 'SW','SE'))
1281+
lines, labels = thetagrids(range(45,360,90), ('NE', 'NW', 'SW','SE'))
12851282
"""
12861283
ax=gca()
12871284
ifnotisinstance(ax,PolarAxes):
1288-
raiseRuntimeError('rgrids only defined for polar axes')
1289-
iflen(args)==0:
1285+
raiseRuntimeError("rgrids only defined for polar axes")
1286+
iflen(args)==0:
12901287
lines=ax.xaxis.get_ticklines()
12911288
labels=ax.xaxis.get_ticklabels()
12921289
else:
12931290
lines,labels=ax.set_thetagrids(*args,**kwargs)
1294-
1295-
return (silent_list('Line2D thetagridline',lines),
1296-
silent_list('Text thetagridlabel',labels)
1297-
)
1298-
1291+
return (silent_list("Line2D thetagridline",lines),
1292+
silent_list("Text thetagridlabel",labels))
12991293

13001294
## Plotting Info ##
13011295

@@ -1362,16 +1356,15 @@ def colors():
13621356
Here is an example that creates a pale turquoise title::
13631357
13641358
title('Is this the best color?', color='#afeeee')
1365-
13661359
"""
1367-
pass
13681360

13691361

13701362
defcolormaps():
13711363
"""
13721364
Matplotlib provides a number of colormaps, and others can be added using
1373-
:func:`~matplotlib.cm.register_cmap`. This function documents the built-in
1374-
colormaps, and will also return a list of all registered colormaps if called.
1365+
`~matplotlib.cm.register_cmap`. This function documents the built-in
1366+
colormaps, and will also return a list of all registered colormaps if
1367+
called.
13751368
13761369
You can set the colormap for an image, pcolor, scatter, etc,
13771370
using a keyword argument::
@@ -1628,7 +1621,7 @@ def pad(s, l):
16281621
exclude= {"colormaps","colors","connect","disconnect",
16291622
"get_current_fig_manager","ginput","plotting",
16301623
"waitforbuttonpress"}
1631-
commands=sorted(set(__all__)-exclude-set(colormaps()))
1624+
commands=sorted(set(__all__)-exclude-set(colormaps()))
16321625

16331626
first_sentence=re.compile(r"(?:\s*).+?\.(?:\s+|$)",flags=re.DOTALL)
16341627

@@ -1676,9 +1669,7 @@ def colorbar(mappable=None, cax=None, ax=None, **kw):
16761669
'with contourf).')
16771670
ifaxisNone:
16781671
ax=gca()
1679-
1680-
ret=gcf().colorbar(mappable,cax=cax,ax=ax,**kw)
1681-
returnret
1672+
returngcf().colorbar(mappable,cax=cax,ax=ax,**kw)
16821673
colorbar.__doc__=matplotlib.colorbar.colorbar_doc
16831674

16841675

@@ -1743,7 +1734,6 @@ def matshow(A, fignum=None, **kw):
17431734
kwarg to "lower" if you want the first row in the array to be
17441735
at the bottom instead of the top.
17451736
1746-
17471737
*fignum*: [ None | integer | False ]
17481738
By default, :func:`matshow` creates a new figure window with
17491739
automatic numbering. If *fignum* is given as an integer, the
@@ -1758,9 +1748,9 @@ def matshow(A, fignum=None, **kw):
17581748
iffignumisFalseorfignumis0:
17591749
ax=gca()
17601750
else:
1761-
# Extract actual aspect ratio of array andmake appropriately sized figure
1751+
# Extractarray'sactual aspect ratio;make appropriately sized figure.
17621752
fig=figure(fignum,figsize=figaspect(A))
1763-
ax=fig.add_axes([0.15,0.09,0.775,0.775])
1753+
ax=fig.add_axes([0.15,0.09,0.775,0.775])
17641754

17651755
im=ax.matshow(A,**kw)
17661756
sci(im)

‎pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pep8ignore =
6666
matplotlib/mathtext.py E201 E202 E203 E211 E221 E222 E225 E228 E231 E251 E261 E301 E302 E303 E401 E402 E501
6767
matplotlib/patheffects.py E231
6868
matplotlib/pylab.py E401 E402 E501
69-
matplotlib/pyplot.pyE201 E202 E203 E221 E222 E225 E231 E251 E261E302E303 E501 E701 E713
69+
matplotlib/pyplot.py E302E305
7070
matplotlib/rcsetup.py E203 E225 E261 E302 E501
7171
matplotlib/stackplot.py E251
7272
matplotlib/transforms.py E201 E202 E203 E302 E501

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp