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

Appearance settings

Commit f87cb25

Browse filesBrowse files
committed
Merge pull request #1376 from NelleV/pep8_table
PEP8 fixes on table.py
2 parents 806e525 + 6766b56 commit f87cb25
Copy full SHA for f87cb25

File tree

Expand file treeCollapse file tree

1 file changed

+59
-52
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+59
-52
lines changed

‎lib/matplotlib/table.py

Copy file name to clipboardExpand all lines: lib/matplotlib/table.py
+59-52Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from transforms import Bbox
3232

3333

34-
3534
class Cell(Rectangle):
3635
"""
3736
A cell is a Rectangle with some associated text.
@@ -49,18 +48,17 @@ def __init__(self, xy, width, height,
4948

5049
# Call base
5150
Rectangle.__init__(self, xy, width=width, height=height,
52-
edgecolor=edgecolor, facecolor=facecolor,
53-
)
51+
edgecolor=edgecolor, facecolor=facecolor)
5452
self.set_clip_on(False)
5553

5654
# Create text object
57-
if loc is None: loc = 'right'
55+
if loc is None:
56+
loc = 'right'
5857
self._loc = loc
5958
self._text = Text(x=xy[0], y=xy[1], text=text,
6059
fontproperties=fontproperties)
6160
self._text.set_clip_on(False)
6261

63-
6462
def set_transform(self, trans):
6563
Rectangle.set_transform(self, trans)
6664
# the text does not get the transform!
@@ -93,7 +91,8 @@ def auto_set_font_size(self, renderer):
9391

9492
@allow_rasterization
9593
def draw(self, renderer):
96-
if not self.get_visible(): return
94+
if not self.get_visible():
95+
return
9796
# draw the rectangle
9897
Rectangle.draw(self, renderer)
9998

@@ -134,14 +133,14 @@ def get_text_bounds(self, renderer):
134133

135134
def get_required_width(self, renderer):
136135
""" Get width required for this cell. """
137-
l,b,w,h = self.get_text_bounds(renderer)
136+
l, b, w, h = self.get_text_bounds(renderer)
138137
return w * (1.0 + (2.0 * self.PAD))
139138

140-
141139
def set_text_props(self, **kwargs):
142140
'update the text properties with kwargs'
143141
self._text.update(kwargs)
144142

143+
145144
class Table(Artist):
146145
"""
147146
Create a table of cells.
@@ -155,25 +154,24 @@ class Table(Artist):
155154
Return value is a sequence of text, line and patch instances that make
156155
up the table
157156
"""
158-
codes = {'best' : 0,
159-
'upper right' : 1, # default
160-
'upper left' : 2,
161-
'lower left' : 3,
162-
'lower right' : 4,
163-
'center left' : 5,
164-
'center right' : 6,
165-
'lower center' : 7,
166-
'upper center' : 8,
167-
'center' : 9,
168-
169-
'top right' : 10,
170-
'top left' : 11,
171-
'bottom left' : 12,
172-
'bottom right' : 13,
173-
'right' : 14,
174-
'left' : 15,
175-
'top' : 16,
176-
'bottom' : 17,
157+
codes = {'best': 0,
158+
'upper right': 1, # default
159+
'upper left': 2,
160+
'lower left': 3,
161+
'lower right': 4,
162+
'center left': 5,
163+
'center right': 6,
164+
'lower center': 7,
165+
'upper center': 8,
166+
'center': 9,
167+
'top right': 10,
168+
'top left': 11,
169+
'bottom left': 12,
170+
'bottom right': 13,
171+
'right': 14,
172+
'left': 15,
173+
'top': 16,
174+
'bottom': 17,
177175
}
178176

179177
FONTSIZE = 10
@@ -184,9 +182,12 @@ def __init__(self, ax, loc=None, bbox=None):
184182
Artist.__init__(self)
185183

186184
if is_string_like(loc) and loc not in self.codes:
187-
warnings.warn('Unrecognized location %s. Falling back on bottom; valid locations are\n%s\t' %(loc, '\n\t'.join(self.codes.iterkeys())))
185+
warnings.warn('Unrecognized location %s. Falling back on '
186+
'bottom; valid locations are\n%s\t' %
187+
(loc, '\n\t'.join(self.codes.iterkeys())))
188188
loc = 'bottom'
189-
if is_string_like(loc): loc = self.codes.get(loc, 1)
189+
if is_string_like(loc):
190+
loc = self.codes.get(loc, 1)
190191
self.set_figure(ax.figure)
191192
self._axes = ax
192193
self._loc = loc
@@ -205,7 +206,7 @@ def __init__(self, ax, loc=None, bbox=None):
205206

206207
def add_cell(self, row, col, *args, **kwargs):
207208
""" Add a cell to the table. """
208-
xy = (0,0)
209+
xy = (0, 0)
209210

210211
cell = Cell(xy, *args, **kwargs)
211212
cell.set_figure(self.figure)
@@ -215,18 +216,21 @@ def add_cell(self, row, col, *args, **kwargs):
215216
self._cells[(row, col)] = cell
216217

217218
def _approx_text_height(self):
218-
return self.FONTSIZE/72.0*self.figure.dpi/self._axes.bbox.height * 1.2
219+
return (self.FONTSIZE / 72.0 * self.figure.dpi /
220+
self._axes.bbox.height * 1.2)
219221

220222
@allow_rasterization
221223
def draw(self, renderer):
222-
# Need a renderer to do hit tests on mouseevent; assume the last one will do
224+
# Need a renderer to do hit tests on mouseevent; assume the last one
225+
# will do
223226
if renderer is None:
224227
renderer = self._cachedRenderer
225228
if renderer is None:
226229
raise RuntimeError('No renderer defined')
227230
self._cachedRenderer = renderer
228231

229-
if not self.get_visible(): return
232+
if not self.get_visible():
233+
return
230234
renderer.open_group('table')
231235
self._update_positions(renderer)
232236

@@ -249,24 +253,25 @@ def _get_grid_bbox(self, renderer):
249253
bbox = Bbox.union(boxes)
250254
return bbox.inverse_transformed(self.get_transform())
251255

252-
def contains(self,mouseevent):
256+
def contains(self, mouseevent):
253257
"""Test whether the mouse event occurred in the table.
254258
255259
Returns T/F, {}
256260
"""
257261
if callable(self._contains):
258-
return self._contains(self,mouseevent)
262+
return self._contains(self, mouseevent)
259263

260264
# TODO: Return index of the cell containing the cursor so that the user
261265
# doesn't have to bind to each one individually.
262266
if self._cachedRenderer is not None:
263267
boxes = [self._cells[pos].get_window_extent(self._cachedRenderer)
264268
for pos in self._cells.iterkeys()
265269
if pos[0] >= 0 and pos[1] >= 0]
270+
# FIXME bbox_all is not defined.
266271
bbox = bbox_all(boxes)
267-
return bbox.contains(mouseevent.x,mouseevent.y),{}
272+
return bbox.contains(mouseevent.x, mouseevent.y), {}
268273
else:
269-
return False,{}
274+
return False, {}
270275

271276
def get_children(self):
272277
'Return the Artists contained by the table'
@@ -276,6 +281,7 @@ def get_children(self):
276281
def get_window_extent(self, renderer):
277282
'Return the bounding box of the table in window coords'
278283
boxes = [c.get_window_extent(renderer) for c in self._cells]
284+
# FIXME bbox_all is not defined
279285
return bbox_all(boxes)
280286

281287
def _do_cell_alignment(self):
@@ -346,7 +352,8 @@ def _auto_set_font_size(self, renderer):
346352
cells = []
347353
for key, cell in self._cells.iteritems():
348354
# ignore auto-sized columns
349-
if key[1] in self._autoColumns: continue
355+
if key[1] in self._autoColumns:
356+
continue
350357
size = cell.auto_set_font_size(renderer)
351358
fontsize = min(fontsize, size)
352359
cells.append(cell)
@@ -376,8 +383,8 @@ def _offset(self, ox, oy):
376383

377384
for c in self._cells.itervalues():
378385
x, y = c.get_x(), c.get_y()
379-
c.set_x(x+ox)
380-
c.set_y(y+oy)
386+
c.set_x(x + ox)
387+
c.set_y(y + oy)
381388

382389
def _update_positions(self, renderer):
383390
# called from renderer to allow more precise estimates of
@@ -394,12 +401,12 @@ def _update_positions(self, renderer):
394401
self._do_cell_alignment()
395402

396403
bbox = self._get_grid_bbox(renderer)
397-
l,b,w,h = bbox.bounds
404+
l, b, w, h = bbox.bounds
398405

399406
if self._bbox is not None:
400407
# Position according to bbox
401408
rl, rb, rw, rh = self._bbox
402-
self.scale(rw/w, rh/h)
409+
self.scale(rw / w, rh / h)
403410
ox = rl - l
404411
oy = rb - b
405412
self._do_cell_alignment()
@@ -408,8 +415,8 @@ def _update_positions(self, renderer):
408415
(BEST, UR, UL, LL, LR, CL, CR, LC, UC, C,
409416
TR, TL, BL, BR, R, L, T, B) = range(len(self.codes))
410417
# defaults for center
411-
ox = (0.5-w/2)-l
412-
oy = (0.5-h/2)-b
418+
ox = (0.5 - w / 2) - l
419+
oy = (0.5 - h / 2) - b
413420
if self._loc in (UL, LL, CL): # left
414421
ox = self.AXESPAD - l
415422
if self._loc in (BEST, UR, LR, R, CR): # right
@@ -419,26 +426,26 @@ def _update_positions(self, renderer):
419426
if self._loc in (LL, LR, LC): # lower
420427
oy = self.AXESPAD - b
421428
if self._loc in (LC, UC, C): # center x
422-
ox = (0.5-w/2)-l
429+
ox = (0.5 - w / 2) - l
423430
if self._loc in (CL, CR, C): # center y
424-
oy = (0.5-h/2)-b
431+
oy = (0.5 - h / 2) - b
425432

426433
if self._loc in (TL, BL, L): # out left
427-
ox = - (l + w)
434+
ox = - (l + w)
428435
if self._loc in (TR, BR, R): # out right
429436
ox = 1.0 - l
430437
if self._loc in (TR, TL, T): # out top
431438
oy = 1.0 - b
432439
if self._loc in (BL, BR, B): # out bottom
433-
oy = - (b + h)
440+
oy = - (b + h)
434441

435442
self._offset(ox, oy)
436443

437-
438444
def get_celld(self):
439445
'return a dict of cells in the table'
440446
return self._cells
441447

448+
442449
def table(ax,
443450
cellText=None, cellColours=None,
444451
cellLoc='right', colWidths=None,
@@ -477,7 +484,7 @@ def table(ax,
477484

478485
# Set colwidths if not given
479486
if colWidths is None:
480-
colWidths = [1.0/cols] * cols
487+
colWidths = [1.0 / cols] * cols
481488

482489
# Check row and column labels
483490
rowLabelWidth = 0
@@ -514,7 +521,7 @@ def table(ax,
514521
# Add the cells
515522
for row in xrange(rows):
516523
for col in xrange(cols):
517-
table.add_cell(row+offset, col,
524+
table.add_cell(row + offset, col,
518525
width=colWidths[col], height=height,
519526
text=cellText[row][col],
520527
facecolor=cellColours[row][col],
@@ -530,7 +537,7 @@ def table(ax,
530537
# Do row labels
531538
if rowLabels is not None:
532539
for row in xrange(rows):
533-
table.add_cell(row+offset, -1,
540+
table.add_cell(row + offset, -1,
534541
width=rowLabelWidth or 1e-15, height=height,
535542
text=rowLabels[row], facecolor=rowColours[row],
536543
loc=rowLoc)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.