Adding tables

Hi John, could you also subscribe to matplotlib-devel and CC the
messages to me (matplotlib-devel sometimes has a long lag). It would
be nice to have these discussions there for archival purposes and so
that others can offer suggestions. Hopefully, you'll have an easier
time getting sighed up there than you did on matplotlib-users.

    > John, First the good news. I've had a good read of
    > legend.py and now pretty much understand how it is working.

Excellent, between the 2 of us, that makes at least one person who
understands that code <wink>.

    > Now the bad news. The way I'm thinking about these tables
    > is that I will want to draw them below the main plot area,
    > sort of where the xticklabels go at the moment + the area
    > below.

But you should try and code it generally so people can place them
wherever they want right? Perhaps you should construct the table with
a list of horizontal lines and a list of vertical lines and their
respective transforms (see below). Or are you already doing this?

    > Now I tried hacking about a table.py copy of legend.py and
    > drawing a grid of lines in this area -- the code runs fine
    > but I don't get a nice grid of lines :frowning: (see snippet of code
    > below).

    > If I cheat and arrange for the drawing to take place within
    > the main plot (by carefully fixing the ypos stuff below)
    > then things work fine.

    > I'm guessing I need to do something to let matplotlib know
    > the extent of what I'm drawing, but I am at a loss as to
    > what that something is.

    > Can you point me in the right direction?

Without a complete code example, I can only guess. My guess is that
you are using the wrong transforms. Each axis instance has a
transAxis and a transData attribute you can use. When you want to
specify a coordinate in axis units (0,1), use the transAxis instance.
If you want to specify a coordinate in data units, use transData.

Eg, if you want the vertical lines (x coords) of your table to line up
with the xticks and the horizontal lines (y coords) of your table to
be in axis units (eg 10% of the axis apart), you would initialize your
line like

   ypos = 0.1 # 10% of axes height
   line = Line2D( self.dpi, self.bbox,
        xdata=(xpos, xpos), ydata=(0, ypos),
        color='k', linestyle=':',
        transx = self.axes.xaxis.transData,
        transy = self.axes.yaxis.transAxis,
       )

Make sure you turn clipping off (it appears you did for your
examples), particularly while developing.

    > (aside: it did occur to me that one way i could cheat an
    > nearly get what i want is to use the bar() method to draw my
    > grid + then use the text() method to enter all the text I
    > want in the grid...)

Cheating is usually a bad thing. I think you'll need to construct
your own text instances with the same x and y transforms you use for
your lines, eg, x coordinate in data units and y coordinate in axis
units. This will also encapsulate the table as a single instance which
will make it easier to manipulate; eg to set text properties for the
entire table.

Hope this helps, if not send me a complete example with demo script
and I can take a closer look.

JDH

John,

Thanks for the hints.

First I’ve tried subscribing to the devel list – sourceforge is sulking again, so no joy so far, i’ve cc’ed the list on this, so if it accepts posts from non-subcribees it should get there.

I’ve looked a bit at the transforms stuff + things are making a bit more sense, but I’m still unable to achieve what I’d like.

I think the basic problem is that Line2D and Rectangle are intended to draw on the axes, whereas what I’d ideally like to do is draw outside the axes (see the screenshot i sent originally) – ie instead of doing what is done with the legend and have it appear somewhere within the axes of the plot I’d like the table of data to be outside this.

I was hoping I could do things like specify negative y-positions to draw below the axes, but I now think I’m deluded in thinking this 'cos matplotlib is smart and every time something gets drawn the axes are automagically adjusted to make sure the latest lines/rectangles are included.

I suspect I need some new sort of object to draw outside the axes - can you confirm that is the case?

Plan B. would be to just live with putting the tables within the plot, as per the legend, but this doesn’t work too well in general 'cos the table tends to obscure some important part of the plot.

Let me know if this is still hard to understand and I’ll try and get what I have into a state which demonstrates the problem I am running into.

John