Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aadd0e0

Browse files
authored
Merge pull request #10542 from timhoffm/minor-cleanup-pep8-pep257
Minor cleanup: PEP8, PEP257
2 parents d7ac70a + eb07c30 commit aadd0e0

File tree

2 files changed

+20
-90
lines changed

2 files changed

+20
-90
lines changed

lib/matplotlib/pyplot.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@
7373

7474
## Backend detection ##
7575
def _backend_selection():
76-
""" If rcParams['backend_fallback'] is true, check to see if the
77-
current backend is compatible with the current running event
78-
loop, and if not switches to a compatible one.
76+
"""
77+
If rcParams['backend_fallback'] is true, check to see if the
78+
current backend is compatible with the current running event loop,
79+
and if not switches to a compatible one.
7980
"""
8081
backend = rcParams['backend']
8182
if not rcParams['backend_fallback'] or backend not in _interactive_bk:
@@ -103,6 +104,7 @@ def _backend_selection():
103104
# import Tkinter
104105
pass # what if anything do we need to do for tkinter?
105106

107+
106108
_backend_selection()
107109

108110
## Global ##
@@ -169,7 +171,7 @@ def post_execute():
169171

170172
def uninstall_repl_displayhook():
171173
"""
172-
Uninstalls the matplotlib display hook.
174+
Uninstall the matplotlib display hook.
173175
174176
.. warning
175177
@@ -249,20 +251,18 @@ def show(*args, **kw):
249251

250252

251253
def isinteractive():
252-
"""
253-
Return status of interactive mode.
254-
"""
254+
"""Return the status of interactive mode."""
255255
return matplotlib.is_interactive()
256256

257257

258258
def ioff():
259-
"""Turn interactive mode off."""
259+
"""Turn the interactive mode off."""
260260
matplotlib.interactive(False)
261261
uninstall_repl_displayhook()
262262

263263

264264
def ion():
265-
"""Turn interactive mode on."""
265+
"""Turn the interactive mode on."""
266266
matplotlib.interactive(True)
267267
install_repl_displayhook()
268268

@@ -675,9 +675,7 @@ def close(*args):
675675

676676

677677
def clf():
678-
"""
679-
Clear the current figure.
680-
"""
678+
"""Clear the current figure."""
681679
gcf().clf()
682680

683681

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,26 @@ def get_tick_iterators(self, axes):
109109
"""
110110

111111
class _Base(object):
112-
"""
113-
Base class for axis helper.
114-
"""
112+
"""Base class for axis helper."""
115113
def __init__(self):
116-
"""
117-
"""
118114
self.delta1, self.delta2 = 0.00001, 0.00001
119115

120116
def update_lim(self, axes):
121117
pass
122118

123-
124119
class Fixed(_Base):
125-
"""
126-
Helper class for a fixed (in the axes coordinate) axis.
127-
"""
120+
"""Helper class for a fixed (in the axes coordinate) axis."""
128121

129122
_default_passthru_pt = dict(left=(0, 0),
130123
right=(1, 0),
131124
bottom=(0, 0),
132125
top=(0, 1))
133126

134-
def __init__(self,
135-
loc, nth_coord=None,
136-
):
127+
def __init__(self, loc, nth_coord=None):
137128
"""
138129
nth_coord = along which coordinate value varies
139130
in 2d, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
140131
"""
141-
142132
self._loc = loc
143133

144134
if loc not in ["left", "right", "bottom", "top"]:
@@ -156,8 +146,6 @@ def __init__(self,
156146

157147
self.passthru_pt = self._default_passthru_pt[loc]
158148

159-
160-
161149
_verts = np.array([[0., 0.],
162150
[1., 1.]])
163151
fixed_coord = 1-nth_coord
@@ -166,7 +154,6 @@ def __init__(self,
166154
# axis line in transAxes
167155
self._path = Path(_verts)
168156

169-
170157
def get_nth_coord(self):
171158
return self.nth_coord
172159

@@ -197,8 +184,6 @@ def get_axislabel_pos_angle(self, axes):
197184

198185
return pos, angle_tangent
199186

200-
201-
202187
# TICK
203188

204189
def get_tick_transform(self, axes):
@@ -221,8 +206,6 @@ def get_line(self, axes):
221206
raise RuntimeError("get_line method should be defined by the derived class")
222207

223208

224-
225-
226209
class AxisArtistHelperRectlinear(object):
227210

228211
class Fixed(AxisArtistHelper.Fixed):
@@ -275,8 +258,6 @@ def _f(locs, labels):
275258

276259
return _f(majorLocs, majorLabels), _f(minorLocs, minorLabels)
277260

278-
279-
280261
class Floating(AxisArtistHelper.Floating):
281262
def __init__(self, axes, nth_coord,
282263
passingthrough_point, axis_direction="bottom"):
@@ -331,12 +312,9 @@ def get_axislabel_pos_angle(self, axes):
331312
else:
332313
return _verts, angle
333314

334-
335-
336315
def get_tick_transform(self, axes):
337316
return axes.transData
338317

339-
340318
def get_tick_iterators(self, axes):
341319
"""tick_loc, tick_angle, tick_label"""
342320

@@ -352,7 +330,7 @@ def get_tick_iterators(self, axes):
352330
else:
353331
angle_normal, angle_tangent = 0, 90
354332

355-
#angle = 90 - 90 * self.nth_coord
333+
# angle = 90 - 90 * self.nth_coord
356334

357335
major = self.axis.major
358336
majorLocs = major.locator()
@@ -381,17 +359,13 @@ def _f(locs, labels):
381359
return _f(majorLocs, majorLabels), _f(minorLocs, minorLabels)
382360

383361

384-
385-
386-
387362
class GridHelperBase(object):
388363

389364
def __init__(self):
390365
self._force_update = True
391366
self._old_limits = None
392367
super().__init__()
393368

394-
395369
def update_lim(self, axes):
396370
x1, x2 = axes.get_xlim()
397371
y1, y2 = axes.get_ylim()
@@ -401,18 +375,15 @@ def update_lim(self, axes):
401375
self._force_update = False
402376
self._old_limits = (x1, x2, y1, y2)
403377

404-
405378
def _update(self, x1, x2, y1, y2):
406379
pass
407380

408-
409381
def invalidate(self):
410382
self._force_update = True
411383

412384
def valid(self):
413385
return not self._force_update
414386

415-
416387
def get_gridlines(self, which, axis):
417388
"""
418389
Return list of grid lines as a list of paths (list of points).
@@ -447,14 +418,10 @@ def new_gridlines(self, ax):
447418

448419
class GridHelperRectlinear(GridHelperBase):
449420

450-
451421
def __init__(self, axes):
452-
453422
super().__init__()
454423
self.axes = axes
455424

456-
457-
458425
def new_fixed_axis(self, loc,
459426
nth_coord=None,
460427
axis_direction=None,
@@ -476,7 +443,6 @@ def new_fixed_axis(self, loc,
476443

477444
return axisline
478445

479-
480446
def new_floating_axis(self, nth_coord, value,
481447
axis_direction="bottom",
482448
axes=None,
@@ -499,40 +465,32 @@ def new_floating_axis(self, nth_coord, value,
499465
axisline.line.set_clip_box(axisline.axes.bbox)
500466
return axisline
501467

502-
503468
def get_gridlines(self, which="major", axis="both"):
504469
"""
505470
return list of gridline coordinates in data coordinates.
506471
507472
*which* : "major" or "minor"
508473
*axis* : "both", "x" or "y"
509474
"""
510-
511475
gridlines = []
512476

513-
514477
if axis in ["both", "x"]:
515478
locs = []
516479
y1, y2 = self.axes.get_ylim()
517-
#if self.axes.xaxis._gridOnMajor:
518480
if which in ["both", "major"]:
519481
locs.extend(self.axes.xaxis.major.locator())
520-
#if self.axes.xaxis._gridOnMinor:
521482
if which in ["both", "minor"]:
522483
locs.extend(self.axes.xaxis.minor.locator())
523484

524485
for x in locs:
525486
gridlines.append([[x, x], [y1, y2]])
526487

527-
528488
if axis in ["both", "y"]:
529489
x1, x2 = self.axes.get_xlim()
530490
locs = []
531491
if self.axes.yaxis._gridOnMajor:
532-
#if which in ["both", "major"]:
533492
locs.extend(self.axes.yaxis.major.locator())
534493
if self.axes.yaxis._gridOnMinor:
535-
#if which in ["both", "minor"]:
536494
locs.extend(self.axes.yaxis.minor.locator())
537495

538496
for y in locs:
@@ -541,10 +499,6 @@ def get_gridlines(self, which="major", axis="both"):
541499
return gridlines
542500

543501

544-
545-
546-
547-
548502
class SimpleChainedObjects(object):
549503
def __init__(self, objects):
550504
self._objects = objects
@@ -581,24 +535,13 @@ def __getitem__(self, k):
581535
def __call__(self, *v, **kwargs):
582536
return maxes.Axes.axis(self.axes, *v, **kwargs)
583537

584-
585-
def __init__(self, *kl, **kw):
586-
587-
588-
helper = kw.pop("grid_helper", None)
589-
538+
def __init__(self, *args, grid_helper=None, **kwargs):
590539
self._axisline_on = True
591-
592-
if helper:
593-
self._grid_helper = helper
594-
else:
595-
self._grid_helper = GridHelperRectlinear(self)
596-
597-
super().__init__(*kl, **kw)
598-
540+
self._grid_helper = (grid_helper if grid_helper
541+
else GridHelperRectlinear(self))
542+
super().__init__(*args, **kwargs)
599543
self.toggle_axisline(True)
600544

601-
602545
def toggle_axisline(self, b=None):
603546
if b is None:
604547
b = not self._axisline_on
@@ -615,11 +558,9 @@ def toggle_axisline(self, b=None):
615558
self.xaxis.set_visible(True)
616559
self.yaxis.set_visible(True)
617560

618-
619561
def _init_axis(self):
620562
super()._init_axis()
621563

622-
623564
def _init_axis_artists(self, axes=None):
624565
if axes is None:
625566
axes = self
@@ -651,19 +592,14 @@ def new_gridlines(self, grid_helper=None):
651592
grid_helper = self.get_grid_helper()
652593

653594
gridlines = grid_helper.new_gridlines(self)
654-
655595
return gridlines
656596

657-
658597
def _init_gridlines(self, grid_helper=None):
659598
# It is done inside the cla.
660-
gridlines = self.new_gridlines(grid_helper)
661-
662-
self.gridlines = gridlines
599+
self.gridlines = self.new_gridlines(grid_helper)
663600

664601
def cla(self):
665602
# gridlines need to b created before cla() since cla calls grid()
666-
667603
self._init_gridlines()
668604
super().cla()
669605

@@ -676,7 +612,6 @@ def cla(self):
676612
def get_grid_helper(self):
677613
return self._grid_helper
678614

679-
680615
def grid(self, b=None, which='major', axis="both", **kwargs):
681616
"""
682617
Toggle the gridlines, and optionally set the properties of the lines.
@@ -715,7 +650,6 @@ def get_children(self):
715650
def invalidate_grid_helper(self):
716651
self._grid_helper.invalidate()
717652

718-
719653
def new_fixed_axis(self, loc, offset=None):
720654
gh = self.get_grid_helper()
721655
axis = gh.new_fixed_axis(loc,
@@ -727,9 +661,7 @@ def new_fixed_axis(self, loc, offset=None):
727661
return axis
728662

729663

730-
def new_floating_axis(self, nth_coord, value,
731-
axis_direction="bottom",
732-
):
664+
def new_floating_axis(self, nth_coord, value, axis_direction="bottom"):
733665
gh = self.get_grid_helper()
734666
axis = gh.new_floating_axis(nth_coord, value,
735667
axis_direction=axis_direction,

0 commit comments

Comments
 (0)