@@ -276,17 +276,52 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
276276 self .set_clip_on (False )
277277
278278 def add_cell (self , row , col , * args , ** kwargs ):
279- """ Add a cell to the table. """
280- xy = (0 , 0 )
279+ """
280+ Add a cell to the table.
281+
282+ Parameters
283+ ----------
284+ row : int
285+ Row index
286+ col : int
287+ Column index
288+
289+ Returns
290+ -------
291+ `CustomCell`: Automatically created cell
281292
293+ """
294+ xy = (0 , 0 )
282295 cell = CustomCell (xy , visible_edges = self .edges , * args , ** kwargs )
296+ self [row , col ] = cell
297+ return cell
298+
299+ def __setitem__ (self , position , cell ):
300+ """
301+ Set a customcell in a given position
302+ """
303+ if not isinstance (cell , CustomCell ):
304+ raise TypeError ('Table only accepts CustomCell' )
305+ try :
306+ row , col = position [0 ], position [1 ]
307+ except Exception :
308+ raise KeyError ('Only tuples length 2 are accepted as coordinates' )
283309 cell .set_figure (self .figure )
284310 cell .set_transform (self .get_transform ())
285-
286311 cell .set_clip_on (False )
287312 self ._cells [row , col ] = cell
288313 self .stale = True
289314
315+ def __getitem__ (self , position ):
316+ """
317+ Retreive a custom cell from a given position
318+ """
319+ try :
320+ row , col = position [0 ], position [1 ]
321+ except Exception :
322+ raise KeyError ('Only tuples length 2 are accepted as coordinates' )
323+ return self ._cells [row , col ]
324+
290325 @property
291326 def edges (self ):
292327 return self ._edges
0 commit comments