@@ -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
@@ -215,9 +224,7 @@ def visible_edges(self, value):
215
224
self .stale = True
216
225
217
226
def get_path (self ):
218
- """
219
- Return a path where the edges specified by _visible_edges are drawn.
220
- """
227
+ """Return a `.Path` for the `.visible_edges`."""
221
228
codes = [Path .MOVETO ]
222
229
223
230
for edge in self ._edges :
@@ -238,13 +245,7 @@ def get_path(self):
238
245
239
246
class Table (Artist ):
240
247
"""
241
- Create a table of cells.
242
-
243
- Table can have (optional) row and column headers.
244
-
245
- Each entry in the table can be either text or patches.
246
-
247
- Column widths and row heights for the table can be specified.
248
+ A table of cells.
248
249
249
250
The table consists of a grid of cells, which are indexed by (row, column).
250
251
@@ -254,8 +255,8 @@ class Table(Artist):
254
255
You don't have to add a cell to every grid position, so you can create
255
256
tables that have holes.
256
257
257
- Return value is a sequence of text, line and patch instances that make
258
- up the table
258
+ *Note*: You'll usually not create an empty table from scratch. Instead use
259
+ `~matplotlib.table.table` to create a table from data.
259
260
"""
260
261
codes = {'best' : 0 ,
261
262
'upper right' : 1 , # default
@@ -276,11 +277,31 @@ class Table(Artist):
276
277
'top' : 16 ,
277
278
'bottom' : 17 ,
278
279
}
280
+ """Possible values where to place the table relative to the Axes."""
279
281
280
282
FONTSIZE = 10
281
- AXESPAD = 0.02 # the border between the axes and table edge
283
+
284
+ AXESPAD = 0.02
285
+ """The border between the Axes and the table edge in Axes units."""
282
286
283
287
def __init__ (self , ax , loc = None , bbox = None , ** kwargs ):
288
+ """
289
+ Parameters
290
+ ----------
291
+ ax : `matplotlib.axes.Axes`
292
+ The `~.axes.Axes` to plot the table into.
293
+ loc : str
294
+ The position of the cell with respect to *ax*. This must be one of
295
+ the `~.Table.codes`.
296
+ bbox : `.Bbox` or None
297
+ A bounding box to draw the table into. If this is not *None*, this
298
+ overrides *loc*.
299
+
300
+ Other Parameters
301
+ ----------------
302
+ **kwargs
303
+ `.Artist` properties.
304
+ """
284
305
285
306
Artist .__init__ (self )
286
307
@@ -313,18 +334,21 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
313
334
314
335
def add_cell (self , row , col , * args , ** kwargs ):
315
336
"""
316
- Add a cell to the table.
337
+ Create a cell and add it to the table.
317
338
318
339
Parameters
319
340
----------
320
341
row : int
321
342
Row index.
322
343
col : int
323
344
Column index.
345
+ *args, **kwargs
346
+ All other parameters are passed on to `Cell`.
324
347
325
348
Returns
326
349
-------
327
- `CustomCell`: Automatically created cell
350
+ cell : `.CustomCell`
351
+ The created cell.
328
352
329
353
"""
330
354
xy = (0 , 0 )
@@ -354,6 +378,21 @@ def __getitem__(self, position):
354
378
355
379
@property
356
380
def edges (self ):
381
+ """
382
+ The default value of `~.CustomCell.visible_edges` for newly added
383
+ cells using `.add_cell`.
384
+
385
+ Notes
386
+ -----
387
+ This setting does currently only affect newly created cells using
388
+ `.add_cell`.
389
+
390
+ To change existing cells, you have to set their edges explicitly::
391
+
392
+ for c in tab.get_celld().values():
393
+ c.visible_edges = 'horizontal'
394
+
395
+ """
357
396
return self ._edges
358
397
359
398
@edges .setter
@@ -367,6 +406,8 @@ def _approx_text_height(self):
367
406
368
407
@allow_rasterization
369
408
def draw (self , renderer ):
409
+ # docstring inherited
410
+
370
411
# Need a renderer to do hit tests on mouseevent; assume the last one
371
412
# will do
372
413
if renderer is None :
@@ -396,10 +437,7 @@ def _get_grid_bbox(self, renderer):
396
437
return bbox .inverse_transformed (self .get_transform ())
397
438
398
439
def contains (self , mouseevent ):
399
- """Test whether the mouse event occurred in the table.
400
-
401
- Returns T/F, {}
402
- """
440
+ # docstring inherited
403
441
if callable (self ._contains ):
404
442
return self ._contains (self , mouseevent )
405
443
@@ -459,26 +497,13 @@ def _do_cell_alignment(self):
459
497
cell .set_y (bottoms [row ])
460
498
461
499
def auto_set_column_width (self , col ):
462
- """ Given column indexs in either List, Tuple or int. Will be able to
463
- automatically set the columns into optimal sizes.
464
-
465
- Here is the example of the input, which triger automatic adjustment on
466
- columns to optimal size by given index numbers.
467
- -1: the row labling
468
- 0: the 1st column
469
- 1: the 2nd column
470
-
471
- Args:
472
- col(List): list of indexs
473
- >>>table.auto_set_column_width([-1,0,1])
474
-
475
- col(Tuple): tuple of indexs
476
- >>>table.auto_set_column_width((-1,0,1))
477
-
478
- col(int): index integer
479
- >>>table.auto_set_column_width(-1)
480
- >>>table.auto_set_column_width(0)
481
- >>>table.auto_set_column_width(1)
500
+ """
501
+ Automatically set the widths of given columns to optimal sizes.
502
+
503
+ Parameters
504
+ ----------
505
+ col : int or sequence of ints
506
+ The indices of the columns to auto-scale.
482
507
"""
483
508
# check for col possibility on iteration
484
509
try :
@@ -529,7 +554,7 @@ def _auto_set_font_size(self, renderer):
529
554
cell .set_fontsize (fontsize )
530
555
531
556
def scale (self , xscale , yscale ):
532
- """ Scale column widths by xscale and row heights by yscale. """
557
+ """Scale column widths by * xscale* and row heights by * yscale*. """
533
558
for c in self ._cells .values ():
534
559
c .set_width (c .get_width () * xscale )
535
560
c .set_height (c .get_height () * yscale )
@@ -541,8 +566,20 @@ def set_fontsize(self, size):
541
566
Parameters
542
567
----------
543
568
size : float
544
- """
545
569
570
+ Notes
571
+ -----
572
+ As long as auto font size has not been disabled, the value will be
573
+ clipped such that the text fits horizontally into the cell.
574
+
575
+ You can disable this behavior using `.auto_set_font_size`.
576
+
577
+ >>> the_table.auto_set_font_size(False)
578
+ >>> the_table.set_fontsize(20)
579
+
580
+ However, there is no automatic scaling of the row height so that the
581
+ text may exceed the cell boundary.
582
+ """
546
583
for cell in self ._cells .values ():
547
584
cell .set_fontsize (size )
548
585
self .stale = True
@@ -610,7 +647,18 @@ def _update_positions(self, renderer):
610
647
self ._offset (ox , oy )
611
648
612
649
def get_celld (self ):
613
- """Return a dict of cells in the table."""
650
+ r"""
651
+ Return a dict of cells in the table mapping *(row, column)* to
652
+ `.Cell`\s.
653
+
654
+ Notes
655
+ -----
656
+ You can also directly index into the Table object to access individual
657
+ cells::
658
+
659
+ cell = table[row, col]
660
+
661
+ """
614
662
return self ._cells
615
663
616
664
@@ -622,13 +670,75 @@ def table(ax,
622
670
loc = 'bottom' , bbox = None , edges = 'closed' ,
623
671
** kwargs ):
624
672
"""
625
- TABLE(cellText=None, cellColours=None,
626
- cellLoc='right', colWidths=None,
627
- rowLabels=None, rowColours=None, rowLoc='left',
628
- colLabels=None, colColours=None, colLoc='center',
629
- loc='bottom', bbox=None, edges='closed')
673
+ Add a table to an `~.axes.Axes`.
674
+
675
+ At least one of *cellText* or *cellColours* must be specified. These
676
+ parameters must be 2D lists, in which the outer lists define the rows and
677
+ the inner list define the column values per row. Each row must have the
678
+ same number of elements.
679
+
680
+ The table can optionally have row and column headers, which are configured
681
+ using *rowLabels*, *rowColours*, *rowLoc* and *colLabels*, *colColours*,
682
+ *colLoc* respectively.
683
+
684
+ Parameters
685
+ ----------
686
+ cellText : 2D list of str, optional
687
+ The texts to place into the table cells.
688
+
689
+ *Note*: Line breaks in the strings are currently not accounted for and
690
+ will result in the text exceeding the cell boundaries.
691
+
692
+ cellColours : 2D list of matplotlib color specs, optional
693
+ The background colors of the cells.
694
+
695
+ cellLoc : {'left', 'center', 'right'}, default: 'right'
696
+ The alignment of the text within the cells.
697
+
698
+ colWidths : list of float, optional
699
+ The column widths in units of the axes. If not given, all columns will
700
+ have a width of *1 / ncols*.
701
+
702
+ rowLabels : list of str, optional
703
+ The text of the row header cells.
704
+
705
+ rowColours : list of matplotlib color specs, optional
706
+ The colors of the row header cells.
707
+
708
+ rowLoc : {'left', 'center', 'right'}, optional, default: 'left'
709
+ The text alignment of the row header cells.
710
+
711
+ colLabels : list of str, optional
712
+ The text of the column header cells.
713
+
714
+ colColours : list of matplotlib color specs, optional
715
+ The colors of the column header cells.
716
+
717
+ rowLoc : {'left', 'center', 'right'}, optional, default: 'left'
718
+ The text alignment of the column header cells.
719
+
720
+ loc : str, optional
721
+ The position of the cell with respect to *ax*. This must be one of
722
+ the `~.Table.codes`.
723
+
724
+ bbox : `.Bbox`, optional
725
+ A bounding box to draw the table into. If this is not *None*, this
726
+ overrides *loc*.
727
+
728
+ edges : substring of 'BRTL' or {'open', 'closed', 'horizontal', 'vertical'}
729
+ The cell edges to be drawn with a line. See also
730
+ `~.CustomCell.visible_edges`.
731
+
732
+ Other Parameters
733
+ ----------------
734
+ **kwargs
735
+ `.Artist` properties.
736
+
737
+ Returns
738
+ -------
739
+ table : `~matplotlib.table.Table`
740
+ The created table.
630
741
631
- Factory function to generate a Table instance.
632
742
"""
633
743
634
744
if cellColours is None and cellText is None :
0 commit comments