29
29
30
30
from . import artist
31
31
from .artist import Artist , allow_rasterization
32
- from .patches import Rectangle
32
+ from .patches import Rectangle , Polygon
33
33
from .cbook import is_string_like
34
34
from matplotlib import docstring
35
35
from .text import Text
@@ -145,6 +145,31 @@ def set_text_props(self, **kwargs):
145
145
'update the text properties with kwargs'
146
146
self ._text .update (kwargs )
147
147
148
+ class SciCell (Cell ):
149
+
150
+ @allow_rasterization
151
+ def draw (self , renderer ):
152
+ if not self .get_visible ():
153
+ return
154
+
155
+ bbox = Rectangle .get_bbox (self )
156
+ x , y , w , h = bbox .bounds
157
+
158
+ topLineVertices = [[x , y ],[x + w , y ]]
159
+ botLineVertices = [[x , y + h ],[x + w , y + h ]]
160
+
161
+ topLine = Polygon (topLineVertices )
162
+ botLine = Polygon (botLineVertices )
163
+
164
+ topLine .update_from (self )
165
+ botLine .update_from (self )
166
+
167
+ topLine .draw (renderer )
168
+ botLine .draw (renderer )
169
+
170
+ # position the text
171
+ self ._set_text_position (renderer )
172
+ self ._text .draw (renderer )
148
173
149
174
class Table (Artist ):
150
175
"""
@@ -211,12 +236,17 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
211
236
self .set_clip_on (False )
212
237
213
238
self ._cachedRenderer = None
239
+ self ._cellType = 'default'
214
240
215
241
def add_cell (self , row , col , * args , ** kwargs ):
216
242
""" Add a cell to the table. """
217
243
xy = (0 , 0 )
218
244
219
- cell = Cell (xy , * args , ** kwargs )
245
+ if self ._cellType == 'default' :
246
+ cell = Cell (xy , * args , ** kwargs )
247
+ else :
248
+ cell = SciCell (xy , * args , ** kwargs )
249
+
220
250
cell .set_figure (self .figure )
221
251
cell .set_transform (self .get_transform ())
222
252
@@ -453,16 +483,27 @@ def get_celld(self):
453
483
'return a dict of cells in the table'
454
484
return self ._cells
455
485
486
+ def get_cell_type (self ):
487
+ return self ._cellType
488
+
489
+ def set_cell_type (self , cellType ):
490
+ if cellType in ('default' , 'scicell' ):
491
+ self ._cellType = cellType
492
+
493
+ else :
494
+ raise ValueError ('Unrecognized cell type %s; '
495
+ 'try default or scicell' % cellType )
496
+
456
497
457
498
def table (ax ,
458
- cellText = None , cellColours = None ,
499
+ cellType = None , cellText = None , cellColours = None ,
459
500
cellLoc = 'right' , colWidths = None ,
460
501
rowLabels = None , rowColours = None , rowLoc = 'left' ,
461
502
colLabels = None , colColours = None , colLoc = 'center' ,
462
503
loc = 'bottom' , bbox = None ,
463
504
** kwargs ):
464
505
"""
465
- TABLE(cellText=None, cellColours=None,
506
+ TABLE(cellType='default', cellText=None, cellColours=None,
466
507
cellLoc='right', colWidths=None,
467
508
rowLabels=None, rowColours=None, rowLoc='left',
468
509
colLabels=None, colColours=None, colLoc='center',
@@ -472,6 +513,9 @@ def table(ax,
472
513
473
514
Thanks to John Gill for providing the class and table.
474
515
"""
516
+ if cellType is not None :
517
+ assert cellType in ('default' , 'scicell' )
518
+
475
519
# Check we have some cellText
476
520
if cellText is None :
477
521
# assume just colours are needed
@@ -529,6 +573,9 @@ def table(ax,
529
573
# Now create the table
530
574
table = Table (ax , loc , bbox , ** kwargs )
531
575
height = table ._approx_text_height ()
576
+
577
+ if cellType is not None :
578
+ table .set_cell_type (cellType )
532
579
533
580
# Add the cells
534
581
for row in xrange (rows ):
0 commit comments