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

Skip to content

Commit fbdc81a

Browse files
committed
pull request fixes for issue #4044
1 parent 3249f50 commit fbdc81a

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

lib/matplotlib/table.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ class SciCell(Cell):
152152
153153
"""
154154

155-
def __init__(self, *args, **kwargs):
156-
157-
# Call base
158-
Cell.__init__(self, *args, **kwargs)
159-
160155
@allow_rasterization
161156
def draw(self, renderer):
162157
if not self.get_visible():
@@ -248,15 +243,13 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
248243

249244
self._cachedRenderer = None
250245
self._cellType = 'default'
246+
self._cellCreation = {"default" : Cell, "scicell" : SciCell}
251247

252248
def add_cell(self, row, col, *args, **kwargs):
253249
""" Add a cell to the table. """
254250
xy = (0, 0)
255251

256-
if self._cellType == 'default':
257-
cell = Cell(xy, *args, **kwargs)
258-
else:
259-
cell = SciCell(xy, *args, **kwargs)
252+
cell = self._cellCreation[self._cellType](xy, *args, **kwargs)
260253

261254
cell.set_figure(self.figure)
262255
cell.set_transform(self.get_transform())
@@ -494,24 +487,29 @@ def get_celld(self):
494487
'return a dict of cells in the table'
495488
return self._cells
496489

497-
def get_cell_type(self):
490+
@property
491+
def cellType(self):
498492
return self._cellType
499493

500-
def set_cell_type(self, cellType):
501-
if cellType in ('default', 'scicell'):
494+
@cellType.setter
495+
def cellType(self, cellType):
496+
if cellType is None:
497+
self._cellType = 'default'
498+
499+
elif cellType in ('default', 'scicell'):
502500
self._cellType = cellType
503501

504502
else:
505-
raise ValueError('Unrecognized cell type %s; '
506-
'Has to be default or scicell' % cellType)
503+
raise ValueError('Unrecognized cellType %s; '
504+
'must be "default" or "scicell"' % cellType)
507505

508506

509507
def table(ax,
510-
cellType=None, cellText=None, cellColours=None,
508+
cellText=None, cellColours=None,
511509
cellLoc='right', colWidths=None,
512510
rowLabels=None, rowColours=None, rowLoc='left',
513511
colLabels=None, colColours=None, colLoc='center',
514-
loc='bottom', bbox=None,
512+
loc='bottom', bbox=None, cellType=None,
515513
**kwargs):
516514
"""
517515
TABLE(cellType='default', cellText=None, cellColours=None,
@@ -524,8 +522,8 @@ def table(ax,
524522
525523
Thanks to John Gill for providing the class and table.
526524
"""
527-
if cellType is not None:
528-
assert cellType in ('default', 'scicell')
525+
if cellType is not None and cellType not in ('default', 'scicell'):
526+
raise ValueError('cellType must be "default" or "scicell" instead of %s ' % cellType)
529527

530528
# Check we have some cellText
531529
if cellText is None:
@@ -584,9 +582,7 @@ def table(ax,
584582
# Now create the table
585583
table = Table(ax, loc, bbox, **kwargs)
586584
height = table._approx_text_height()
587-
588-
if cellType is not None:
589-
table.set_cell_type(cellType)
585+
table.cellType = cellType
590586

591587
# Add the cells
592588
for row in xrange(rows):

0 commit comments

Comments
 (0)