On Fri, Feb 18, 2011 at 2:41 AM, andrea crotti <andrea.crott...@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?
> Thanks,
> Andrea
>
>
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:

http://matplotlib.sourceforge.net/users/annotations.html

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:

http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.text.Text.get_bbox_patch
http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.text.Text.get_window_extent

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
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to