def format_figure(figure=None, tall=False, draw=True, modify_geometry=True):
_pylab.ioff()<EOL>if figure == None: figure = _pylab.gcf()<EOL>if modify_geometry:<EOL><INDENT>if tall: set_figure_window_geometry(figure, (<NUM_LIT:0>,<NUM_LIT:0>), (<NUM_LIT>,<NUM_LIT>))<EOL>else:    set_figure_window_geometry(figure, (<NUM_LIT:0>,<NUM_LIT:0>), (<NUM_LIT>,<NUM_LIT>))<EOL><DEDENT>legend_position=<NUM_LIT><EOL>ymin = <NUM_LIT:1.0><EOL>ymax = <NUM_LIT:0.0><EOL>xmin = <NUM_LIT:1.0><EOL>xmax = <NUM_LIT:0.0><EOL>for axes in figure.get_axes():<EOL><INDENT>(x,y,dx,dy) = axes.get_position().bounds<EOL>if y    < ymin: ymin = y<EOL>if y+dy > ymax: ymax = y+dy<EOL>if x    < xmin: xmin = x<EOL>if x+dx > xmax: xmax = x+dx<EOL><DEDENT>w = <NUM_LIT><EOL>h = <NUM_LIT><EOL>bb = <NUM_LIT><EOL>bl = <NUM_LIT><EOL>xscale = w / (xmax-xmin)<EOL>yscale = h / (ymax-ymin)<EOL>current_axes = _pylab.gca()<EOL>for axes in figure.get_axes():<EOL><INDENT>(x,y,dx,dy) = axes.get_position().bounds<EOL>y  = bb + (y-ymin)*yscale<EOL>dy = dy * yscale<EOL>x  = bl + (x-xmin)*xscale<EOL>dx = dx * xscale<EOL>axes.set_position([x,y,dx,dy])<EOL>_pylab.axes(axes) <EOL>if len(axes.lines)><NUM_LIT:0>:<EOL><INDENT>_pylab.legend(loc=[legend_position, <NUM_LIT:0>], borderpad=<NUM_LIT>, prop=_FontProperties(size=<NUM_LIT:7>))<EOL><DEDENT>if axes.get_legend():<EOL><INDENT>axes.get_legend().labelsep = <NUM_LIT><EOL>axes.get_legend().set_visible(<NUM_LIT:1>)<EOL><DEDENT>axes.title.set_horizontalalignment('<STR_LIT:right>')<EOL>axes.title.set_size(<NUM_LIT:8>)<EOL>axes.title.set_position([<NUM_LIT>,<NUM_LIT>])<EOL>axes.title.set_visible(<NUM_LIT:1>)<EOL><DEDENT>_pylab.axes(current_axes)<EOL>if draw:<EOL><INDENT>_pylab.ion()<EOL>_pylab.draw()<EOL><DEDENT>
This formats the figure in a compact way with (hopefully) enough useful
information for printing large data sets. Used mostly for line and scatter
plots with long, information-filled titles.

Chances are somewhat slim this will be ideal for you but it very well might
and is at least a good starting point.

figure=None     specify a figure object. None will use gcf()