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.

Example

from pylab import *
f = figure()
f.add_subplot(111)
f.tight_layout()
show()

Hope it helps.

Cheers

Answer 2


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