TAGS :Viewed: 2 - Published at: a few seconds ago

[ How do I set the size of the axes patch so that the plot labels aren't clipped (matplotlib) ]

I have a graph in which I've set the axis labels to scientific notation using

formatter = mpl.ticker.FormatStrFormatter('%4.2e') axis2.yaxis.set_major_formatter(formatter)

However, the axes.patch (or whatever is the right way to express the 'canvas' extent of the plot) doesn't adjust so the tick labels and axis label are clipped:

enter image description here

How do I adjust the extent of the axes portion of the plot. Changing the page size (figsize = ...) doesn't do it, since that just scales the overall plot area, resulting in the same clipping problem.

Answer 1

You can use the method tight_layout, which will accommodate the plot in the figure available space.


from pylab import *
f = figure()

Hope it helps.


Answer 2

Just call fig.tight_layout() (assuming you have a Figure object defined).