Llaves
Llaves

Reputation: 743

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.

Upvotes: 0

Views: 318

Answers (2)

mrcl
mrcl

Reputation: 2190

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

Upvotes: 1

Paul H
Paul H

Reputation: 68156

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

Upvotes: 0

Related Questions