One more related thing: is there any way to retrieve the size of a textbox
in figure coordinates, something like
ax.get_ymajorticklabels[0].get_width()?
This is not very easy since the renderer is not known until the figure
is drawn. After the window is drawn and the text instance knows its
renderer, you can call t.get_window_extent(). So you would likely
want to connect to the "on_draw" method and get the window extent
there, and then do something with it, eg move the left of the canvas
over. Here is a recursive, iterative solution that will gradually
move the left of the subplot over until the label fits w/o going
outside the figure border (requires 0.98)::
import matplotlib.pyplot as plt
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):
for label in labels:
bbox = label.get_window_extent()
if bbox.xmin<0:
print 'adjusting left of subplot'
fig.subplots_adjust(left=1.1*fig.subplotpars.left)
fig.canvas.draw()
break
fig.canvas.mpl_connect('draw_event', on_draw)
plt.show()
Also, I'm kind of wondering why things like set_text() on that doesn't work.
In general I haven't had much success with editing the properties of objects
like this.
The tick labels are a bit special, since they are generated on the fly
(eg if you are panning and zooming, new ticks must be created and sold
ones destroyed). So you can't set their text directly, but rather
need to create a tick locator and a tick formatter as described in
Users Guide Chapter 6 -
http://matplotlib.sourceforge.net/users_guide_0.98.0.pdf and the
examples
http://matplotlib.sourceforge.net/examples/pylab/custom_ticker1.py
http://matplotlib.sourceforge.net/examples/pylab/major_minor_demo1.py
JDH
···
On Wed, Jun 18, 2008 at 2:42 PM, David Warde-Farley <dwf@...386...> wrote: