On Fri, Jun 20, 2008 at 9:32 PM, David Warde-Farley <[EMAIL PROTECTED]> wrote:
> Thanks again for the help. I was wondering about the code you posted --
> what's the problem with say, using bbox.xmin to adjust left only once? Or
> else perhaps get_text_width_height from the renderer? Wouldn't that yield
> the desired effect without the iterative procedure, since you'd immediately
> know (roughly) how much to push the subplot over?
Yes, that is a better approach. But you need to do a little work to
get the coordinate system width (going from width in pixels to
fractional width). Here is an example:
mport matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(10))
ax.set_yticks((2,5,7))
labels = ax.set_yticklabels(('really, really, really', 'long', 'labels'))
def on_draw(event):
bboxes = []
for label in labels:
bbox = label.get_window_extent()
# the figure transform goes from relative coords->pixels and we
# want the inverse of that
bboxi = bbox.inverse_transformed(fig.transFigure)
bboxes.append(bboxi)
# this is the bbox that bounds all the bboxes, again in relative
# figure coords
bbox = mtransforms.Bbox.union(bboxes)
if fig.subplotpars.left < bbox.width:
# we need to move it over
fig.subplots_adjust(left=1.1*bbox.width) # pad a little
fig.canvas.draw()
return False
fig.canvas.mpl_connect('draw_event', on_draw)
plt.show()
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users