|
From: Goyo <goy...@gm...> - 2012-08-19 18:13:03
|
2012/8/19 Peter Combs <pco...@gm...>: > Hi all, > I'm trying to have a Text object with a fancy box, as in this example: > http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/fancybox_demo2.py > . However, the key difference is that I want to have the box (in my case, > I'm interested in an RArrow) be a specified width (in units of the plot), > rather than just fitting it to the text I've given (crude ascii art below). > The following seems not to work: > > > ax = gca() > txtobj = ax.text(0, -.1 * yrange, 'text', > bbox=dict(boxstyle='rarrow')) > txtobj.get_bbox_patch().set_ > width(SIZE_IM_INTERESTED_IN) > draw_if_interactive() > > It seems like draw()ing the text object will reset the size of the BBox... > Any idea how to fix this? At the moment, I'm experimenting with continually > drawing, polling the get_width() method, and when it's too small, adding in > spaces around the text field, but that seems both not to work reliably, and > be an incredibly boneheaded way to go about it. Not ideal but better: from pyplot import * subplot(111) text(0.1, 0.3, 'XXXXXXXXXXXXXXX', alpha=0, bbox=dict(boxstyle='rarrow')) text(0.1, 0.3, 'short') text(0.1, 0.6, 'XXXXXXXXXXXXXXX', alpha=0, bbox=dict(boxstyle='rarrow')) text(0.1, 0.6, 'looooooooooong') show() Goyo |