Automatic subplot_params for fitting label text (was Re: [Matplotlib-users] Suggestions for auto scaling fonts ,

etc for producing images at various scales)
In-Reply-To: <20110121232036.GA26739@...905...>

Paul Ivanov, on 2011-01-21 15:20, wrote:

I'm almost certain that one *can* write a function to do this
pro grammatically (without having to hand tweak anything), by
looking at say, the .get_window_extent() but I haven't found the
time to scratch that itch, yet.

If someone wants to beat me to it, here's the sort of thing that
you can do:

  def show_labels_by_shrinking(ax):
    " adjust subplot parameters to fit the yaxis label"
    f = ax.figure
    textwidth = ax.yaxis.get_label().get_window_extent().width
    labelwidth = max([lab.get_window_extent().width for lab in ax.get_yticklabels()])
    # the 3 *ax.yaxis.labelpad is just a fudge factor for now, need
    # to look into the sourcecode to figure out what the
    # appropriate placement is normally, to know how to adjust
    # properly

I should add that along with doing a similar thing for the xaxis,
this would need to be extended for the multiple subplot case, to
also adjust the wspace and hspace parameters accordingly.

this is important functionality currently missing from matplotlib
out-of-the-box at the moment, so I'll try my crack at it this out
this weekend.

CCing the devel list in case someone has more opinions.



Paul Ivanov
314 address only used for lists, off-list direct email at: | GPG/PGP key id: 0x0F3E28F7