@@ -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 `. Cell` subclass 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,31 @@ 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 in Axes units."""
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
+ """
285
306
286
307
Artist .__init__ (self )
287
308
@@ -314,18 +335,21 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
314
335
315
336
def add_cell (self , row , col , * args , ** kwargs ):
316
337
"""
317
- Add a cell to the table.
338
+ Create a cell and add it to the table.
318
339
319
340
Parameters
320
341
----------
321
342
row : int
322
343
Row index.
323
344
col : int
324
345
Column index.
346
+ *args, **kwargs
347
+ All other parameters are passed on to `Cell`.
325
348
326
349
Returns
327
350
-------
328
- `CustomCell`: Automatically created cell
351
+ cell : `.CustomCell`
352
+ The created cell.
329
353
330
354
"""
331
355
xy = (0 , 0 )
@@ -361,6 +385,21 @@ def __getitem__(self, position):
361
385
362
386
@property
363
387
def edges (self ):
388
+ """
389
+ The default value of `~.CustomCell.visible_edges` for newly added
390
+ cells using `.add_cell`.
391
+
392
+ Notes
393
+ -----
394
+ This setting does currently only affect newly created cells using
395
+ `.add_cell`.
396
+
397
+ To change existing cells, you have to set their edges explicitly::
398
+
399
+ for c in tab.get_celld().values():
400
+ c.visible_edges = 'horizontal'
401
+
402
+ """
364
403
return self ._edges
365
404
366
405
@edges .setter
@@ -374,6 +413,8 @@ def _approx_text_height(self):
374
413
375
414
@allow_rasterization
376
415
def draw (self , renderer ):
416
+ # docstring inherited
417
+
377
418
# Need a renderer to do hit tests on mouseevent; assume the last one
378
419
# will do
379
420
if renderer is None :
@@ -403,10 +444,7 @@ def _get_grid_bbox(self, renderer):
403
444
return bbox .inverse_transformed (self .get_transform ())
404
445
405
446
def contains (self , mouseevent ):
406
- """Test whether the mouse event occurred in the table.
407
-
408
- Returns T/F, {}
409
- """
447
+ # docstring inherited
410
448
if callable (self ._contains ):
411
449
return self ._contains (self , mouseevent )
412
450
@@ -466,26 +504,13 @@ def _do_cell_alignment(self):
466
504
cell .set_y (bottoms [row ])
467
505
468
506
def auto_set_column_width (self , col ):
469
- """ Given column indexs in either List, Tuple or int. Will be able to
470
- automatically set the columns into optimal sizes.
471
-
472
- Here is the example of the input, which triger automatic adjustment on
473
- columns to optimal size by given index numbers.
474
- -1: the row labling
475
- 0: the 1st column
476
- 1: the 2nd column
477
-
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))
484
-
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)
507
+ """
508
+ Automatically set the widths of given columns to optimal sizes.
509
+
510
+ Parameters
511
+ ----------
512
+ col : int or sequence of ints
513
+ The indices of the columns to auto-scale.
489
514
"""
490
515
# check for col possibility on iteration
491
516
try :
@@ -536,7 +561,7 @@ def _auto_set_font_size(self, renderer):
536
561
cell .set_fontsize (fontsize )
537
562
538
563
def scale (self , xscale , yscale ):
539
- """ Scale column widths by xscale and row heights by yscale. """
564
+ """Scale column widths by * xscale* and row heights by * yscale*. """
540
565
for c in self ._cells .values ():
541
566
c .set_width (c .get_width () * xscale )
542
567
c .set_height (c .get_height () * yscale )
@@ -548,8 +573,20 @@ def set_fontsize(self, size):
548
573
Parameters
549
574
----------
550
575
size : float
551
- """
552
576
577
+ Notes
578
+ -----
579
+ As long as auto font size has not been disabled, the value will be
580
+ clipped such that the text fits horizontally into the cell.
581
+
582
+ You can disable this behavior using `.auto_set_font_size`.
583
+
584
+ >>> the_table.auto_set_font_size(False)
585
+ >>> the_table.set_fontsize(20)
586
+
587
+ However, there is no automatic scaling of the row height so that the
588
+ text may exceed the cell boundary.
589
+ """
553
590
for cell in self ._cells .values ():
554
591
cell .set_fontsize (size )
555
592
self .stale = True
@@ -617,7 +654,18 @@ def _update_positions(self, renderer):
617
654
self ._offset (ox , oy )
618
655
619
656
def get_celld (self ):
620
- """Return a dict of cells in the table."""
657
+ r"""
658
+ Return a dict of cells in the table mapping *(row, column)* to
659
+ `.Cell`\s.
660
+
661
+ Notes
662
+ -----
663
+ You can also directly index into the Table object to access individual
664
+ cells::
665
+
666
+ cell = table[row, col]
667
+
668
+ """
621
669
return self ._cells
622
670
623
671
@@ -629,13 +677,75 @@ def table(ax,
629
677
loc = 'bottom' , bbox = None , edges = 'closed' ,
630
678
** kwargs ):
631
679
"""
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')
680
+ Add a table to an `~.axes.Axes`.
681
+
682
+ At least one of *cellText* or *cellColours* must be specified. These
683
+ parameters must be 2D lists, in which the outer lists define the rows and
684
+ the inner list define the column values per row. Each row must have the
685
+ same number of elements.
686
+
687
+ The table can optionally have row and column headers, which are configured
688
+ using *rowLabels*, *rowColours*, *rowLoc* and *colLabels*, *colColours*,
689
+ *colLoc* respectively.
690
+
691
+ Parameters
692
+ ----------
693
+ cellText : 2D list of str, optional
694
+ The texts to place into the table cells.
695
+
696
+ *Note*: Line breaks in the strings are currently not accounted for and
697
+ will result in the text exceeding the cell boundaries.
698
+
699
+ cellColours : 2D list of matplotlib color specs, optional
700
+ The background colors of the cells.
701
+
702
+ cellLoc : {'left', 'center', 'right'}, default: 'right'
703
+ The alignment of the text within the cells.
704
+
705
+ colWidths : list of float, optional
706
+ The column widths in units of the axes. If not given, all columns will
707
+ have a width of *1 / ncols*.
708
+
709
+ rowLabels : list of str, optional
710
+ The text of the row header cells.
711
+
712
+ rowColours : list of matplotlib color specs, optional
713
+ The colors of the row header cells.
714
+
715
+ rowLoc : {'left', 'center', 'right'}, optional, default: 'left'
716
+ The text alignment of the row header cells.
717
+
718
+ colLabels : list of str, optional
719
+ The text of the column header cells.
720
+
721
+ colColours : list of matplotlib color specs, optional
722
+ The colors of the column header cells.
723
+
724
+ rowLoc : {'left', 'center', 'right'}, optional, default: 'left'
725
+ The text alignment of the column header cells.
726
+
727
+ loc : str, optional
728
+ The position of the cell with respect to *ax*. This must be one of
729
+ the `~.Table.codes`.
730
+
731
+ bbox : `.Bbox`, optional
732
+ A bounding box to draw the table into. If this is not *None*, this
733
+ overrides *loc*.
734
+
735
+ edges : substring of 'BRTL' or {'open', 'closed', 'horizontal', 'vertical'}
736
+ The cell edges to be drawn with a line. See also
737
+ `~.CustomCell.visible_edges`.
738
+
739
+ Other Parameters
740
+ ----------------
741
+ **kwargs
742
+ `.Artist` properties.
743
+
744
+ Returns
745
+ -------
746
+ table : `~matplotlib.table.Table`
747
+ The created table.
637
748
638
- Factory function to generate a Table instance.
639
749
"""
640
750
641
751
if cellColours is None and cellText is None :
0 commit comments