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

Commit6bf63d4

Browse files
committed
pep8-ify pyplot.
1 parenta3803c2 commit6bf63d4

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
@@ -63,7 +63,9 @@
6363
MaxNLocator
6464
frommatplotlib.backendsimportpylab_setup
6565

66+
6667
## Backend detection ##
68+
6769
def_backend_selection():
6870
""" If rcParams['backend_fallback'] is true, check to see if the
6971
current backend is compatible with the current running event
@@ -73,7 +75,7 @@ def _backend_selection():
7375
ifnotrcParams['backend_fallback']orbackendnotin_interactive_bk:
7476
return
7577
is_agg_backend=rcParams['backend'].endswith('Agg')
76-
if'wx'insys.modulesandnotbackendin ('WX','WXAgg'):
78+
if'wx'insys.modulesandbackendnotin ('WX','WXAgg'):
7779
importwx
7880
ifwx.App.IsMainLoopRunning():
7981
rcParams['backend']='wx'+'Agg'*is_agg_backend
@@ -223,7 +225,8 @@ def switch_backend(newbackend):
223225
global_backend_mod,new_figure_manager,draw_if_interactive,_show
224226
matplotlib.use(newbackend,warn=False,force=True)
225227
frommatplotlib.backendsimportpylab_setup
226-
_backend_mod,new_figure_manager,draw_if_interactive,_show=pylab_setup()
228+
_backend_mod,new_figure_manager,draw_if_interactive,_show= \
229+
pylab_setup()
227230

228231

229232
defshow(*args,**kw):
@@ -281,10 +284,8 @@ def pause(interval):
281284
else:
282285
time.sleep(interval)
283286

284-
285287
## Any Artist ##
286288

287-
288289
defxkcd(scale=1,length=100,randomness=2):
289290
"""
290291
Turns on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
@@ -357,7 +358,6 @@ def __enter__(self):
357358

358359
returndummy_ctx()
359360

360-
361361
## Figures ##
362362

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

605-
606605
## Axes ##
607606

608-
609607
defaxes(*args,**kwargs):
610608
"""
611609
Add an axes to the figure.
@@ -722,12 +720,13 @@ def subplot(*args, **kwargs):
722720
import matplotlib.pyplot as plt
723721
# plot a line, implicitly creating a subplot(111)
724722
plt.plot([1,2,3])
725-
# now create a subplot which represents the top plot of a grid
726-
#with2 rows and 1 column. Since this subplot will overlap the
727-
#first, theplot (and its axes) previously created, will be removed
723+
# now create a subplot which represents the top plot of a grid with
724+
# 2 rows and 1 column. Since this subplot will overlap the first, the
725+
# plot (and its axes) previously created, will be removed
728726
plt.subplot(211)
729727
plt.plot(range(12))
730-
plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background
728+
# create a second subplot with yellow background
729+
plt.subplot(212, facecolor='y')
731730
732731
If you do not want this behavior, use the
733732
:meth:`~matplotlib.figure.Figure.add_subplot` method or the
@@ -764,28 +763,26 @@ def subplot(*args, **kwargs):
764763
765764
"""
766765
# if subplot called without arguments, create subplot(1,1,1)
767-
iflen(args)==0:
768-
args=(1,1,1)
766+
iflen(args)==0:
767+
args=(1,1,1)
769768

770769
# This check was added because it is very easy to type
771770
# subplot(1, 2, False) when subplots(1, 2, False) was intended
772771
# (sharex=False, that is). In most cases, no error will
773772
# ever occur, but mysterious behavior can result because what was
774773
# intended to be the sharex argument is instead treated as a
775774
# subplot index for subplot()
776-
iflen(args)>=3andisinstance(args[2],bool):
777-
warnings.warn("The subplot index argument to subplot() appears"
778-
"to be a boolean. Did you intend to use subplots()?")
775+
iflen(args)>=3andisinstance(args[2],bool):
776+
warnings.warn("The subplot index argument to subplot() appears"
777+
"to be a boolean. Did you intend to use subplots()?")
779778

780779
fig=gcf()
781780
a=fig.add_subplot(*args,**kwargs)
782781
bbox=a.bbox
783-
byebye= []
784-
forotherinfig.axes:
785-
ifother==a:continue
786-
ifbbox.fully_overlaps(other.bbox):
787-
byebye.append(other)
788-
foraxinbyebye:delaxes(ax)
782+
byebye= [otherforotherinfig.axes
783+
ifotherisnotaandbbox.fully_overlaps(other.bbox)]
784+
foraxinbyebye:
785+
delaxes(ax)
789786

790787
returna
791788

@@ -1007,24 +1004,28 @@ def subplot_tool(targetfig=None):
10071004
"""
10081005
Launch a subplot tool window for a figure.
10091006
1010-
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
1007+
Returns
1008+
-------
1009+
`matplotlib.widgets.SubplotTool`
10111010
"""
1012-
tbar=rcParams['toolbar']# turn off thenavigation toolbar for the toolfig
1013-
rcParams['toolbar']='None'
1011+
tbar=rcParams["toolbar"]# Turn off thenav toolbar for the toolfig.
1012+
rcParams["toolbar"]="None"
10141013
iftargetfigisNone:
10151014
manager=get_current_fig_manager()
10161015
targetfig=manager.canvas.figure
10171016
else:
1018-
#find the manager for this figure
1017+
#Find the manager for this figure.
10191018
formanagerin_pylab_helpers.Gcf._activeQue:
1020-
ifmanager.canvas.figure==targetfig:break
1021-
else:raiseRuntimeError('Could not find manager for targetfig')
1019+
ifmanager.canvas.figure==targetfig:
1020+
break
1021+
else:
1022+
raiseRuntimeError("Could not find manager for targetfig")
10221023

1023-
toolfig=figure(figsize=(6,3))
1024+
toolfig=figure(figsize=(6,3))
10241025
toolfig.subplots_adjust(top=0.9)
1025-
ret=SubplotTool(targetfig,toolfig)
1026-
rcParams['toolbar']=tbar
1027-
_pylab_helpers.Gcf.set_active(manager)#restore the current figure
1026+
ret=SubplotTool(targetfig,toolfig)
1027+
rcParams["toolbar"]=tbar
1028+
_pylab_helpers.Gcf.set_active(manager)#Restore the current figure.
10281029
returnret
10291030

10301031

@@ -1041,10 +1042,8 @@ def box(on=None):
10411042
on=notax.get_frame_on()
10421043
ax.set_frame_on(on)
10431044

1044-
10451045
## Axis ##
10461046

1047-
10481047
defxlim(*args,**kwargs):
10491048
"""
10501049
Get or set the *x* limits of the current axes.
@@ -1209,15 +1208,14 @@ def rgrids(*args, **kwargs):
12091208
"""
12101209
ax=gca()
12111210
ifnotisinstance(ax,PolarAxes):
1212-
raiseRuntimeError('rgrids only defined for polar axes')
1213-
iflen(args)==0:
1211+
raiseRuntimeError("rgrids only defined for polar axes")
1212+
iflen(args)==0:
12141213
lines=ax.yaxis.get_gridlines()
12151214
labels=ax.yaxis.get_ticklabels()
12161215
else:
12171216
lines,labels=ax.set_rgrids(*args,**kwargs)
1218-
1219-
return (silent_list('Line2D rgridline',lines),
1220-
silent_list('Text rgridlabel',labels) )
1217+
return (silent_list("Line2D rgridline",lines),
1218+
silent_list("Text rgridlabel",labels))
12211219

12221220

12231221
defthetagrids(*args,**kwargs):
@@ -1255,31 +1253,27 @@ def thetagrids(*args, **kwargs):
12551253
12561254
- *labels* are :class:`~matplotlib.text.Text` instances.
12571255
1258-
Note that on input, the *labels* argument is a list of strings,
1259-
and on output it is a list of :class:`~matplotlib.text.Text`
1260-
instances.
1256+
Note that on input, the *labels* argument is a list of strings, and on
1257+
output it is a list of :class:`~matplotlib.text.Text` instances.
12611258
12621259
Examples::
12631260
12641261
# set the locations of the radial gridlines and labels
1265-
lines, labels = thetagrids(range(45,360,90))
1262+
lines, labels = thetagrids(range(45,360,90))
12661263
12671264
# set the locations and labels of the radial gridlines and labels
1268-
lines, labels = thetagrids(range(45,360,90), ('NE', 'NW', 'SW','SE'))
1265+
lines, labels = thetagrids(range(45,360,90), ('NE', 'NW', 'SW','SE'))
12691266
"""
12701267
ax=gca()
12711268
ifnotisinstance(ax,PolarAxes):
1272-
raiseRuntimeError('rgrids only defined for polar axes')
1273-
iflen(args)==0:
1269+
raiseRuntimeError("rgrids only defined for polar axes")
1270+
iflen(args)==0:
12741271
lines=ax.xaxis.get_ticklines()
12751272
labels=ax.xaxis.get_ticklabels()
12761273
else:
12771274
lines,labels=ax.set_thetagrids(*args,**kwargs)
1278-
1279-
return (silent_list('Line2D thetagridline',lines),
1280-
silent_list('Text thetagridlabel',labels)
1281-
)
1282-
1275+
return (silent_list("Line2D thetagridline",lines),
1276+
silent_list("Text thetagridlabel",labels))
12831277

12841278
## Plotting Info ##
12851279

@@ -1346,16 +1340,15 @@ def colors():
13461340
Here is an example that creates a pale turquoise title::
13471341
13481342
title('Is this the best color?', color='#afeeee')
1349-
13501343
"""
1351-
pass
13521344

13531345

13541346
defcolormaps():
13551347
"""
13561348
Matplotlib provides a number of colormaps, and others can be added using
1357-
:func:`~matplotlib.cm.register_cmap`. This function documents the built-in
1358-
colormaps, and will also return a list of all registered colormaps if called.
1349+
`~matplotlib.cm.register_cmap`. This function documents the built-in
1350+
colormaps, and will also return a list of all registered colormaps if
1351+
called.
13591352
13601353
You can set the colormap for an image, pcolor, scatter, etc,
13611354
using a keyword argument::
@@ -1612,7 +1605,7 @@ def pad(s, l):
16121605
exclude= {"colormaps","colors","connect","disconnect",
16131606
"get_current_fig_manager","ginput","plotting",
16141607
"waitforbuttonpress"}
1615-
commands=sorted(set(__all__)-exclude-set(colormaps()))
1608+
commands=sorted(set(__all__)-exclude-set(colormaps()))
16161609

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

@@ -1660,9 +1653,7 @@ def colorbar(mappable=None, cax=None, ax=None, **kw):
16601653
'with contourf).')
16611654
ifaxisNone:
16621655
ax=gca()
1663-
1664-
ret=gcf().colorbar(mappable,cax=cax,ax=ax,**kw)
1665-
returnret
1656+
returngcf().colorbar(mappable,cax=cax,ax=ax,**kw)
16661657
colorbar.__doc__=matplotlib.colorbar.colorbar_doc
16671658

16681659

@@ -1727,7 +1718,6 @@ def matshow(A, fignum=None, **kw):
17271718
kwarg to "lower" if you want the first row in the array to be
17281719
at the bottom instead of the top.
17291720
1730-
17311721
*fignum*: [ None | integer | False ]
17321722
By default, :func:`matshow` creates a new figure window with
17331723
automatic numbering. If *fignum* is given as an integer, the
@@ -1742,9 +1732,9 @@ def matshow(A, fignum=None, **kw):
17421732
iffignumisFalseorfignumis0:
17431733
ax=gca()
17441734
else:
1745-
# Extract actual aspect ratio of array andmake appropriately sized figure
1735+
# Extractarray'sactual aspect ratio;make appropriately sized figure.
17461736
fig=figure(fignum,figsize=figaspect(A))
1747-
ax=fig.add_axes([0.15,0.09,0.775,0.775])
1737+
ax=fig.add_axes([0.15,0.09,0.775,0.775])
17481738

17491739
im=ax.matshow(A,**kw)
17501740
sci(im)

‎pytest.ini

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp