Another go at tables.

John, Here is another go at the tables.

Very nice! Soon we'll be able to write matplotlib_excel :slight_smile:

    > I've created a cell object (see cell.py). This is just a
    > rectangle that has some (optional) text associated with it.

A minor comment. Derived artist should implement '_draw', nor 'draw'
as the Artist Base implements the draw method, caches the renderer
instance and then calls _draw. Ie, you want

    def _draw(self, renderer, *args, **kwargs):

        # draw the rectangle
        # use _draw here since this is a base class
        Rectangle._draw(self, renderer, *args, **kwargs)

        # position the text
        self._set_text_position()
        self._text.draw(renderer) # use draw here

I noticed I made the same mistake in text.Text. The 'draw' method
there should be renamed _draw.

The motivation here is that you can redraw any artist w/o access to
the renderer since the Artist base has stored it and will use it if
renderer is None

  instance.draw() # instance is derived from Artist
  
    > A table is now not much more than just a collection of
    > cells.

All very nice. Two things I think would make a nice addition. You've
provided a great selection of default locations. It shouldn't be too
hard to allow 'loc' to be None, and let the user define a bbox (left,
bottom, width, height) in 0-1 coords to place the table wherever they
want it.

Ie, use

class Table
    def __init__(self, axis, loc=None, bbox=None):

The other thing that might would be a nice addition is a function to
autogenerate tables. Eg, you provide it a list of col header strings,
row header strings, color args and an MxN array of cell text strings,
and it does the dirty work of actually building the table for you. If
col header strings is empty, don't do the row at -1, etc...

Thanks! With your permission, I'll include it in the next matplotlib
release.

JDH

See attached.

table.py now has dataTable which does the autogenerating of tables given cells, rows and column stuff and tries to do sensible things if only a subset is actually supplied.

data_table_demo.py is an example of dataTable in action.

I’ve included the latest version of cell.py 'cos I think I’ve added more to that in the last 24 hours as well.

re: including this in the next release, that would be excellent.

john

table.py (10.7 KB)

cell.py (2.71 KB)

data_table_demo.py (2.06 KB)

···
*
All very nice. Two things I think would make a nice addition. You've
provided a great selection of default locations. It shouldn't be too
hard to allow 'loc' to be None, and let the user define a bbox (left,
bottom, width, height) in 0-1 coords to place the table wherever they
want it.
Ie, use
class Table
def __init__(self, axis, loc=None, bbox=None):
The other thing that might would be a nice addition is a function to
autogenerate tables. Eg, you provide it a list of col header strings,
row header strings, color args and an MxN array of cell text strings,
and it does the dirty work of actually building the table for you. If
col header strings is empty, don't do the row at -1, etc...
Thanks! With your permission, I'll include it in the next matplotlib
release.
JDH*