@@ -195,6 +195,10 @@ class Table(Artist):
195
195
'bottom' : 17 ,
196
196
}
197
197
198
+ CELLTYPES = {'default' : Cell ,
199
+ 'scientific' : ScientificCell ,
200
+ }
201
+
198
202
FONTSIZE = 10
199
203
AXESPAD = 0.02 # the border between the axes and table edge
200
204
@@ -219,6 +223,7 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
219
223
220
224
self ._texts = []
221
225
self ._cells = {}
226
+ self ._cellType = 'default'
222
227
self ._autoRows = []
223
228
self ._autoColumns = []
224
229
self ._autoFontsize = True
@@ -232,13 +237,30 @@ def add_cell(self, row, col, *args, **kwargs):
232
237
""" Add a cell to the table. """
233
238
xy = (0 , 0 )
234
239
235
- cell = Cell (xy , * args , ** kwargs )
240
+ cell = self . CELLTYPES [ self . cellType ] (xy , * args , ** kwargs )
236
241
cell .set_figure (self .figure )
237
242
cell .set_transform (self .get_transform ())
238
243
239
244
cell .set_clip_on (False )
240
245
self ._cells [(row , col )] = cell
241
246
247
+ @property
248
+ def cellType (self ):
249
+ return self ._cellType
250
+
251
+ @cellType .setter
252
+ def cellType (self , value ):
253
+ if value is None :
254
+ pass # Leave as previously set
255
+ elif value in self .CELLTYPES :
256
+ self ._cellType = value
257
+ else :
258
+ msg = 'Unrecognized type of Cell: {0}, must be one of {1}.' .format (
259
+ value ,
260
+ ", " .join (self .CELLTYPES .keys ()),
261
+ )
262
+ raise ValueError (msg )
263
+
242
264
def _approx_text_height (self ):
243
265
return (self .FONTSIZE / 72.0 * self .figure .dpi /
244
266
self ._axes .bbox .height * 1.2 )
@@ -470,37 +492,19 @@ def get_celld(self):
470
492
return self ._cells
471
493
472
494
473
- class ScientificTable (Table ):
474
- """
475
- A subclass of Table which uses ScientificCell instead of Cell.
476
-
477
- """
478
-
479
- def add_cell (self , row , col , * args , ** kwargs ):
480
- 'Add a scientific cell to the table.'
481
- xy = (0 , 0 )
482
-
483
- cell = ScientificCell (xy , * args , ** kwargs )
484
- cell .set_figure (self .figure )
485
- cell .set_transform (self .get_transform ())
486
-
487
- cell .set_clip_on (False )
488
- self ._cells [(row , col )] = cell
489
-
490
-
491
495
def table (ax ,
492
496
cellText = None , cellColours = None ,
493
497
cellLoc = 'right' , colWidths = None ,
494
498
rowLabels = None , rowColours = None , rowLoc = 'left' ,
495
499
colLabels = None , colColours = None , colLoc = 'center' ,
496
- loc = 'bottom' , bbox = None , tableType = None ,
500
+ loc = 'bottom' , bbox = None , cellType = None ,
497
501
** kwargs ):
498
502
"""
499
503
TABLE(cellText=None, cellColours=None,
500
504
cellLoc='right', colWidths=None,
501
505
rowLabels=None, rowColours=None, rowLoc='left',
502
506
colLabels=None, colColours=None, colLoc='center',
503
- loc='bottom', bbox=None, tableType =None)
507
+ loc='bottom', bbox=None, cellType =None)
504
508
505
509
Factory function to generate a Table instance.
506
510
@@ -562,11 +566,8 @@ def table(ax,
562
566
cellColours = ['w' * cols ] * rows
563
567
564
568
# Now create the table
565
- if tableType == "scientific" :
566
- table = ScientificTable (ax , loc , bbox , ** kwargs )
567
- else :
568
- table = Table (ax , loc , bbox , ** kwargs )
569
-
569
+ table = Table (ax , loc , bbox , ** kwargs )
570
+ table .cellType = cellType
570
571
height = table ._approx_text_height ()
571
572
572
573
# Add the cells
0 commit comments