axis labels clipped

<quote author="Tony Yu-3">
A while back, I wrote some functions to calculate a good set of parameters for subplots_adjust (see attached; examples in if-main block at bottom). I've been using these functions pretty regularly, and it works pretty well for my purposes.

The function has to draw the figure a couple of times to calculate correct spacing. When redrawing the figure (e.g. when you resize the window), you'd have to re-call the function, which would redraw the figure a couple of times before drawing the final figure. That's all to say: this is a fairly slow function. If you don't have subplots (like in your example), you can call "layout.tight_borders()" (instead of "layout.tight()"), which only requires a single redraw.

When I originally posted this to the developers list, the functions didn't work with the GtkAgg backend. As far as I know, this hasn't changed. It should work fine for Qt4Agg, macosx, and TkAgg backends.
</quote>

Hi Tony,

I copied your layout.py.
Then run the following python script:

···

------------------------------------------------------
import matplotlib.pyplot as plt
import layout
import random

fontsizes = [8, 16, 24, 32]
def example_plot(ax):
     ax.plot([1, 2])
     ax.set_xlabel('x-label', fontsize=random.choice(fontsizes))
     ax.set_ylabel('y-label', fontsize=random.choice(fontsizes))
     ax.set_title('Title', fontsize=random.choice(fontsizes))

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)
example_plot(ax1)
example_plot(ax2)
example_plot(ax3)
example_plot(ax4)

def on_resize(event):
     print( 'on_resize()' )
     layout.tight()

def on_close(event):
     print( 'on_close()' )
     fig.canvas.mpl_disconnect( rsiz_id )
     print rsiz_id

layout.tight()

if False:
#if True:
     rsiz_id = fig.canvas.mpl_connect('resize_event', on_resize)
     print rsiz_id
     fig.canvas.mpl_connect('close_event', on_close)

plt.show()
------------------------------------------------------

Without the resize event it works as expected.
With the resize event (as you suggested),
it only adjusts the borders of the four axes to the outside of the figure.
But between the axes there is no space at all.

Do I miss something?

Thanks a lot

Kurt
--
Kurt Mueller

I think I was saying (I’m not certain, since it’s been a while since the original email) that the function (layout.tight) had to be called again after resizing.

BTW, one of the matplotlib devs (Jae Joon Lee, I believe) completely rewrote/improved this function and added it to matplotlib as tight_layout (both as a pyplot function and a figure method). I’m not sure if the function is in the current mpl release, but there’s a pending release in the works.

Best,
-Tony

···

On Fri, Sep 23, 2011 at 9:01 AM, Kurt Mueller <kurt.alfred.mueller@…287…> wrote:

Without the resize event it works as expected.

With the resize event (as you suggested),

it only adjusts the borders of the four axes to the outside of the figure.

But between the axes there is no space at all.

Do I miss something?