19
19
License : matplotlib license
20
20
21
21
"""
22
- from __future__ import (absolute_import , division , print_function ,
23
- unicode_literals )
24
-
25
- import six
26
-
27
22
import warnings
28
23
29
24
from . import artist
37
32
38
33
class Cell (Rectangle ):
39
34
"""
40
- A cell is a Rectangle with some associated text.
41
-
35
+ A cell is a `.Rectangle` with some associated text.
42
36
"""
43
37
PAD = 0.1 # padding between text and rectangle
44
38
@@ -73,15 +67,15 @@ def set_figure(self, fig):
73
67
self ._text .set_figure (fig )
74
68
75
69
def get_text (self ):
76
- ' Return the cell Text intance'
70
+ """ Return the cell `. Text` instance."""
77
71
return self ._text
78
72
79
73
def set_fontsize (self , size ):
80
74
self ._text .set_fontsize (size )
81
75
self .stale = True
82
76
83
77
def get_fontsize (self ):
84
- ' Return the cell fontsize'
78
+ """ Return the cell fontsize."""
85
79
return self ._text .get_fontsize ()
86
80
87
81
def auto_set_font_size (self , renderer ):
@@ -189,8 +183,9 @@ def visible_edges(self, value):
189
183
self .stale = True
190
184
191
185
def get_path (self ):
192
- 'Return a path where the edges specified by _visible_edges are drawn'
193
-
186
+ """
187
+ Return a path where the edges specified by _visible_edges are drawn.
188
+ """
194
189
codes = [Path .MOVETO ]
195
190
196
191
for edge in self ._edges :
@@ -249,12 +244,12 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
249
244
250
245
Artist .__init__ (self )
251
246
252
- if isinstance (loc , six . string_types ) and loc not in self .codes :
247
+ if isinstance (loc , str ) and loc not in self .codes :
253
248
warnings .warn ('Unrecognized location %s. Falling back on '
254
249
'bottom; valid locations are\n %s\t ' %
255
250
(loc , '\n \t ' .join (self .codes )))
256
251
loc = 'bottom'
257
- if isinstance (loc , six . string_types ):
252
+ if isinstance (loc , str ):
258
253
loc = self .codes .get (loc , 1 )
259
254
self .set_figure (ax .figure )
260
255
self ._axes = ax
@@ -281,9 +276,9 @@ def add_cell(self, row, col, *args, **kwargs):
281
276
Parameters
282
277
----------
283
278
row : int
284
- Row index
279
+ Row index.
285
280
col : int
286
- Column index
281
+ Column index.
287
282
288
283
Returns
289
284
-------
@@ -297,7 +292,7 @@ def add_cell(self, row, col, *args, **kwargs):
297
292
298
293
def __setitem__ (self , position , cell ):
299
294
"""
300
- Set a customcell in a given position
295
+ Set a custom cell in a given position.
301
296
"""
302
297
if not isinstance (cell , CustomCell ):
303
298
raise TypeError ('Table only accepts CustomCell' )
@@ -313,7 +308,7 @@ def __setitem__(self, position, cell):
313
308
314
309
def __getitem__ (self , position ):
315
310
"""
316
- Retreive a custom cell from a given position
311
+ Retrieve a custom cell from a given position.
317
312
"""
318
313
try :
319
314
row , col = position [0 ], position [1 ]
@@ -359,7 +354,7 @@ def _get_grid_bbox(self, renderer):
359
354
360
355
Only include those in the range (0,0) to (maxRow, maxCol)"""
361
356
boxes = [cell .get_window_extent (renderer )
362
- for (row , col ), cell in six . iteritems ( self ._cells )
357
+ for (row , col ), cell in self ._cells . items ( )
363
358
if row >= 0 and col >= 0 ]
364
359
bbox = Bbox .union (boxes )
365
360
return bbox .inverse_transformed (self .get_transform ())
@@ -377,22 +372,22 @@ def contains(self, mouseevent):
377
372
renderer = self .figure ._cachedRenderer
378
373
if renderer is not None :
379
374
boxes = [cell .get_window_extent (renderer )
380
- for (row , col ), cell in six . iteritems ( self ._cells )
375
+ for (row , col ), cell in self ._cells . items ( )
381
376
if row >= 0 and col >= 0 ]
382
377
bbox = Bbox .union (boxes )
383
378
return bbox .contains (mouseevent .x , mouseevent .y ), {}
384
379
else :
385
380
return False , {}
386
381
387
382
def get_children (self ):
388
- ' Return the Artists contained by the table'
389
- return list (six . itervalues ( self ._cells ))
383
+ """ Return the Artists contained by the table."""
384
+ return list (self ._cells . values ( ))
390
385
get_child_artists = get_children # backward compatibility
391
386
392
387
def get_window_extent (self , renderer ):
393
- ' Return the bounding box of the table in window coords'
388
+ """ Return the bounding box of the table in window coords."""
394
389
boxes = [cell .get_window_extent (renderer )
395
- for cell in six . itervalues ( self ._cells )]
390
+ for cell in self ._cells . values ( )]
396
391
return Bbox .union (boxes )
397
392
398
393
def _do_cell_alignment (self ):
@@ -403,7 +398,7 @@ def _do_cell_alignment(self):
403
398
# Calculate row/column widths
404
399
widths = {}
405
400
heights = {}
406
- for (row , col ), cell in six . iteritems ( self ._cells ):
401
+ for (row , col ), cell in self ._cells . items ( ):
407
402
height = heights .setdefault (row , 0.0 )
408
403
heights [row ] = max (height , cell .get_height ())
409
404
width = widths .setdefault (col , 0.0 )
@@ -423,7 +418,7 @@ def _do_cell_alignment(self):
423
418
ypos += heights [row ]
424
419
425
420
# set cell positions
426
- for (row , col ), cell in six . iteritems ( self ._cells ):
421
+ for (row , col ), cell in self ._cells . items ( ):
427
422
cell .set_x (lefts [col ])
428
423
cell .set_y (bottoms [row ])
429
424
@@ -461,8 +456,7 @@ def auto_set_column_width(self, col):
461
456
self .stale = True
462
457
463
458
def _auto_set_column_width (self , col , renderer ):
464
- """ Automagically set width for column.
465
- """
459
+ """Automatically set width for column."""
466
460
cells = [key for key in self ._cells if key [1 ] == col ]
467
461
468
462
# find max width
@@ -484,9 +478,9 @@ def _auto_set_font_size(self, renderer):
484
478
485
479
if len (self ._cells ) == 0 :
486
480
return
487
- fontsize = list ( six . itervalues (self ._cells ))[ 0 ] .get_fontsize ()
481
+ fontsize = next ( iter (self ._cells . values ())) .get_fontsize ()
488
482
cells = []
489
- for key , cell in six . iteritems ( self ._cells ):
483
+ for key , cell in self ._cells . items ( ):
490
484
# ignore auto-sized columns
491
485
if key [1 ] in self ._autoColumns :
492
486
continue
@@ -495,12 +489,12 @@ def _auto_set_font_size(self, renderer):
495
489
cells .append (cell )
496
490
497
491
# now set all fontsizes equal
498
- for cell in six . itervalues ( self ._cells ):
492
+ for cell in self ._cells . values ( ):
499
493
cell .set_fontsize (fontsize )
500
494
501
495
def scale (self , xscale , yscale ):
502
496
""" Scale column widths by xscale and row heights by yscale. """
503
- for c in six . itervalues ( self ._cells ):
497
+ for c in self ._cells . values ( ):
504
498
c .set_width (c .get_width () * xscale )
505
499
c .set_height (c .get_height () * yscale )
506
500
@@ -511,14 +505,13 @@ def set_fontsize(self, size):
511
505
ACCEPTS: a float in points
512
506
"""
513
507
514
- for cell in six . itervalues ( self ._cells ):
508
+ for cell in self ._cells . values ( ):
515
509
cell .set_fontsize (size )
516
510
self .stale = True
517
511
518
512
def _offset (self , ox , oy ):
519
- 'Move all the artists by ox,oy (axes coords)'
520
-
521
- for c in six .itervalues (self ._cells ):
513
+ """Move all the artists by ox, oy (axes coords)."""
514
+ for c in self ._cells .values ():
522
515
x , y = c .get_x (), c .get_y ()
523
516
c .set_x (x + ox )
524
517
c .set_y (y + oy )
@@ -579,7 +572,7 @@ def _update_positions(self, renderer):
579
572
self ._offset (ox , oy )
580
573
581
574
def get_celld (self ):
582
- 'return a dict of cells in the table'
575
+ """Return a dict of cells in the table."""
583
576
return self ._cells
584
577
585
578
0 commit comments