I have slightly modified the example from
http://matplotlib.sourceforge.net/faq/howto_faq.html#automatically-make-room-for-tick-labels
in order to demonstrate what I mean.
It works with the manual string tick labels but not with regular
auto-generated numerical ones.
Maybe someone knows how to fix this? And I *really* think this should
work automatically. As a compromise, maybe an rcParam would help in
order to keep the current dumb behavior...
Thanks in advance,
Daniel
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
fig = plt.figure(figsize=(5,3))
ax = fig.add_subplot(111)
#ax.plot(range(10))
#ax.set_yticks((2,5,7))
#labels = ax.set_yticklabels(('really, really, really', 'long', 'labels'))
ax.plot(range(100),[100000]*100)
labels = ax.get_yticklabels()
def on_draw(event):
bboxes = []
for label in labels:
bbox = label.get_window_extent()
print bbox
# 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()
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users