@@ -180,7 +180,7 @@ def set_text_props(self, **kwargs):
180
180
181
181
class CustomCell (Cell ):
182
182
"""
183
- A subclass of Cell where the sides may be visibly toggled .
183
+ A subclass of `. Cell` with configurable edge visibility .
184
184
"""
185
185
186
186
_edges = 'BRTL'
@@ -196,6 +196,15 @@ def __init__(self, *args, visible_edges, **kwargs):
196
196
197
197
@property
198
198
def visible_edges (self ):
199
+ """
200
+ The cell edges to be drawn with a line.
201
+
202
+ Reading this property returns a substring of 'BRTL' (bottom, right,
203
+ top, left').
204
+
205
+ When setting this property, you can use a substring of 'BRTL' or one
206
+ of {'open', 'closed', 'horizontal', 'vertical'}.
207
+ """
199
208
return self ._visible_edges
200
209
201
210
@visible_edges .setter
@@ -216,9 +225,7 @@ def visible_edges(self, value):
216
225
self .stale = True
217
226
218
227
def get_path (self ):
219
- """
220
- Return a path where the edges specified by _visible_edges are drawn.
221
- """
228
+ """Return a `.Path` for the `.visible_edges`."""
222
229
codes = [Path .MOVETO ]
223
230
224
231
for edge in self ._edges :
@@ -239,13 +246,7 @@ def get_path(self):
239
246
240
247
class Table (Artist ):
241
248
"""
242
- Create a table of cells.
243
-
244
- Table can have (optional) row and column headers.
245
-
246
- Each entry in the table can be either text or patches.
247
-
248
- Column widths and row heights for the table can be specified.
249
+ A table of cells.
249
250
250
251
The table consists of a grid of cells, which are indexed by (row, column).
251
252
@@ -255,8 +256,8 @@ class Table(Artist):
255
256
You don't have to add a cell to every grid position, so you can create
256
257
tables that have holes.
257
258
258
- Return value is a sequence of text, line and patch instances that make
259
- up the table
259
+ *Note*: You'll usually not create an empty table from scratch. Instead use
260
+ `~matplotlib.table.table` to create a table from data.
260
261
"""
261
262
codes = {'best' : 0 ,
262
263
'upper right' : 1 , # default
@@ -277,11 +278,32 @@ class Table(Artist):
277
278
'top' : 16 ,
278
279
'bottom' : 17 ,
279
280
}
281
+ """Possible values where to place the table relative to the Axes."""
280
282
281
283
FONTSIZE = 10
282
- AXESPAD = 0.02 # the border between the axes and table edge
284
+
285
+ AXESPAD = 0.02
286
+ """The border between the Axes and the table edge."""
283
287
284
288
def __init__ (self , ax , loc = None , bbox = None , ** kwargs ):
289
+ """
290
+ Parameters
291
+ ----------
292
+ ax : `matplotlib.axes.Axes`
293
+ The `~axes.Axes` to plot the table into.
294
+ loc : str
295
+ The position of the cell with respect to *ax*. This must be one of
296
+ the `~.Table.codes`.
297
+ bbox : `.Bbox` or None
298
+ A bounding box to draw the table into. If this is not *None*, this
299
+ overrides *loc*.
300
+
301
+ Other Parameters
302
+ ----------------
303
+ **kwargs
304
+ `.Artist` properties.
305
+
306
+ """
285
307
286
308
Artist .__init__ (self )
287
309
@@ -314,18 +336,21 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
314
336
315
337
def add_cell (self , row , col , * args , ** kwargs ):
316
338
"""
317
- Add a cell to the table.
339
+ Create a cell and add it to the table.
318
340
319
341
Parameters
320
342
----------
321
343
row : int
322
344
Row index.
323
345
col : int
324
346
Column index.
347
+ *args, **kwargs
348
+ All other parameters are passed on to `Cell`.
325
349
326
350
Returns
327
351
-------
328
- `CustomCell`: Automatically created cell
352
+ `CustomCell`
353
+ The created cell.
329
354
330
355
"""
331
356
xy = (0 , 0 )
@@ -361,6 +386,21 @@ def __getitem__(self, position):
361
386
362
387
@property
363
388
def edges (self ):
389
+ """
390
+ The default value of `~.CustomCell.visible_edges` for newly added
391
+ cells using `.add_cell`.
392
+
393
+ Notes
394
+ -----
395
+ This setting does currently only affect newly created cells using
396
+ `.add_cell`.
397
+
398
+ To change existing cells, you have to set their edges explicitly:
399
+
400
+ >>> for c in tab.get_celld().values():
401
+ >>> c.visible_edges = 'horizontal'
402
+
403
+ """
364
404
return self ._edges
365
405
366
406
@edges .setter
@@ -374,6 +414,8 @@ def _approx_text_height(self):
374
414
375
415
@allow_rasterization
376
416
def draw (self , renderer ):
417
+ # docstring inherited
418
+
377
419
# Need a renderer to do hit tests on mouseevent; assume the last one
378
420
# will do
379
421
if renderer is None :
@@ -403,10 +445,7 @@ def _get_grid_bbox(self, renderer):
403
445
return bbox .inverse_transformed (self .get_transform ())
404
446
405
447
def contains (self , mouseevent ):
406
- """Test whether the mouse event occurred in the table.
407
-
408
- Returns T/F, {}
409
- """
448
+ # docstring inherited
410
449
if callable (self ._contains ):
411
450
return self ._contains (self , mouseevent )
412
451
@@ -475,17 +514,11 @@ def auto_set_column_width(self, col):
475
514
0: the 1st column
476
515
1: the 2nd column
477
516
478
- Args:
479
- col(List): list of indexs
480
- >>>table.auto_set_column_width([-1,0,1])
481
-
482
- col(Tuple): tuple of indexs
483
- >>>table.auto_set_column_width((-1,0,1))
517
+ Parameters
518
+ ----------
519
+ col : int or sequence of ints
520
+ The indices of the columns to auto-scale.
484
521
485
- col(int): index integer
486
- >>>table.auto_set_column_width(-1)
487
- >>>table.auto_set_column_width(0)
488
- >>>table.auto_set_column_width(1)
489
522
"""
490
523
# check for col possibility on iteration
491
524
try :
@@ -536,7 +569,7 @@ def _auto_set_font_size(self, renderer):
536
569
cell .set_fontsize (fontsize )
537
570
538
571
def scale (self , xscale , yscale ):
539
- """ Scale column widths by xscale and row heights by yscale. """
572
+ """Scale column widths by * xscale* and row heights by * yscale*. """
540
573
for c in self ._cells .values ():
541
574
c .set_width (c .get_width () * xscale )
542
575
c .set_height (c .get_height () * yscale )
@@ -548,8 +581,20 @@ def set_fontsize(self, size):
548
581
Parameters
549
582
----------
550
583
size : float
551
- """
552
584
585
+ Notes
586
+ -----
587
+ As long as auto font size has not been disabled, the value will be
588
+ clipped such that the text will still fit into the table cell.
589
+
590
+ You can disable this behavior Using `.auto_set_font_size`.
591
+
592
+ >>> the_table.auto_set_font_size(False)
593
+ >>> the_table.set_fontsize(20)
594
+
595
+ However, there is no automatic scaling of the row height so that the
596
+ text may exceed the cell boundary.
597
+ """
553
598
for cell in self ._cells .values ():
554
599
cell .set_fontsize (size )
555
600
self .stale = True
@@ -617,7 +662,18 @@ def _update_positions(self, renderer):
617
662
self ._offset (ox , oy )
618
663
619
664
def get_celld (self ):
620
- """Return a dict of cells in the table."""
665
+ r"""
666
+ Return a dict of cells in the table mapping indices *(row, column)* to
667
+ `.Cell`\s.
668
+
669
+ Notes
670
+ -----
671
+ You can also directly index into the Table object to access individual
672
+ cells::
673
+
674
+ cell = table[row, col]
675
+
676
+ """
621
677
return self ._cells
622
678
623
679
@@ -629,13 +685,75 @@ def table(ax,
629
685
loc = 'bottom' , bbox = None , edges = 'closed' ,
630
686
** kwargs ):
631
687
"""
632
- TABLE(cellText=None, cellColours=None,
633
- cellLoc='right', colWidths=None,
634
- rowLabels=None, rowColours=None, rowLoc='left',
635
- colLabels=None, colColours=None, colLoc='center',
636
- loc='bottom', bbox=None, edges='closed')
688
+ Add a table to an `~.axes.Axes`.
689
+
690
+ You have to specify at least one of *cellText* or *cellColours*. These
691
+ parameters must be 2D lists, in which the outer lists define the rows and
692
+ the inner list define the column values per row. Each row must have the
693
+ same number of elements.
694
+
695
+ The table can optionally have row and column headers, which are configured
696
+ using *rowLabels*, *rowColours*, *rowLoc* and *colLabels*, *colColours*,
697
+ *colLoc* respectively.
698
+
699
+ Parameters
700
+ ----------
701
+ cellText : 2D list of str, optional
702
+ The texts to place into the table cells.
703
+
704
+ *Note*: Line breaks in the strings are currently not accounted for and
705
+ will result in the text exceeding the cell boundaries.
706
+
707
+ cellColours : 2D list of matplotlib color specs, optional
708
+ The background colors of the cells.
709
+
710
+ cellLoc : {'left', 'center', 'right'}, default: 'right'
711
+ The alignment of the text within the cells.
712
+
713
+ colWidths : list of float, optional
714
+ The column widths in units of the axes. If not given, all columns will
715
+ have a width of *1 / ncols*.
716
+
717
+ rowLabels : list of str, optional
718
+ The text of the row header cells.
719
+
720
+ rowColours : list of matplotlib color specs, optional
721
+ The colors of the row header cells.
722
+
723
+ rowLoc : {'left', 'center', 'right'}, optional, default: 'left'
724
+ The text alignment of the row header cells.
725
+
726
+ colLabels : list of str, optional
727
+ The text of the column header cells.
728
+
729
+ colColours : list of matplotlib color specs, optional
730
+ The colors of the column header cells.
731
+
732
+ rowLoc : {'left', 'center', 'right'}, optional, default: 'left'
733
+ The text alignment of the column header cells.
734
+
735
+ loc : str, optional
736
+ The position of the cell with respect to *ax*. This must be one of
737
+ the `~.Table.codes`.
738
+
739
+ bbox : `.Bbox`, optional
740
+ A bounding box to draw the table into. If this is not *None*, this
741
+ overrides *loc*.
742
+
743
+ edges : substring of 'BRTL' or {'open', 'closed', 'horizontal', 'vertical'}
744
+ The cell edges to be drawn with a line. See also
745
+ `~.CustomCell.visible_edges`.
746
+
747
+ Other Parameters
748
+ ----------------
749
+ **kwargs
750
+ `.Artist` properties.
751
+
752
+ Returns
753
+ -------
754
+ table : `~matplotlib.table.Table`
755
+ The created table.
637
756
638
- Factory function to generate a Table instance.
639
757
"""
640
758
641
759
if cellColours is None and cellText is None :
0 commit comments