On Fri, Feb 18, 2011 at 2:41 AM, andrea crotti <andrea.crotti.0@gmail.com> wrote:
Hi everyone, and thanks for the amazing library first of all :)

Now a short  question, I have some graphs and I would like to add some statistical summary as text on the figure.

I see how I can add text and it's quite easy, the problem is that the text wants a coordinate to write the graph.

And I can't really know it before since the size of the network (and the axis) are computed and fixed at run-time.
So I should add enough space for the text and then place it, but how do I know how much space it would take?

Automatic layouts are difficult to do in matplotlib.  This was a design decision trade-off made early in its development.  Instead of having matplotlib determining optimal layouts and such, the developers decided that it would be better to give the programmers full control over all placement, and merely establish good defaults.

Just for completeness, I like this page because it talks about the multiple different ways you can specify coordinates for a text object (and corresponding arrow) for placement:


Knowing ahead of time how much space an annotation will take is very difficult, especially if your text involves any LaTeX symbols.  However, it is possible.  The Text object has some method calls that can return bounding boxes for the text object after it is made:


I haven't used these myself, so I don't know exactly what is the difference between them (I think they are different coordinate systems).  Once knowing the size of your text object, you can change the position of the object using its set_position() method.  It is tricky, but if positioning and layout is very important to you, it is possible to do.

I hope this helps!

Ben Root