Axes outer position - amount of space for axes labels

HI,

Is there a way to get the size of the bounding box for the
axes which includes the axes labels and tick marks? It looks like
Axes.get_position/set_position refers to the inner position (i.e the actual
plot area).

In matlab (http://www.mathworks.com/help/techdoc/ref/axes_props.html)
this was the outer and inner position of an axes. I would like to get the outer
position (i.e the yellow box in http://www.mathworks.com/help/techdoc/ref/axes_props.html)

Thanks

Jeremy

Jeremy Lewi

Engineering Scientist

The Intellisis Corporation

jlewi@…2615…

Jeremy,

Yes, get/set_position refers to the position of the plot area within a particular axes area in a figure. I am not exactly aware of how one determines its outer boundary box, because there really isn’t an outer box. Everything within an axes area is plotted within coordinates of 0 to 1. The plot box is set typically at 0.125 to 0.9. Axes labels are then draw as an offset relative to the plot area. This can cause the axes labels and figure titles to overlap each other in neighboring subplots if they get too big.

Tony Yu did make some code to help deal with display issues surrounding the lack of a constrained outer box. See this link for some discussion of it and the code. Maybe it can help you with whatever you need.

http://permalink.gmane.org/gmane.comp.python.matplotlib.general/24652

I hope that helps!
Ben Root

···

On Fri, Sep 17, 2010 at 4:37 PM, Jeremy Lewi <jlewi@…2615…> wrote:

HI,

Is there a way to get the size of the bounding box for the
axes which includes the axes labels and tick marks? It looks like
Axes.get_position/set_position refers to the inner position (i.e the actual
plot area).

In matlab (http://www.mathworks.com/help/techdoc/ref/axes_props.html)
this was the outer and inner position of an axes. I would like to get the outer
position (i.e the yellow box in http://www.mathworks.com/help/techdoc/ref/axes_props.html)

Thanks

Jeremy

Jeremy Lewi

Engineering Scientist

The Intellisis Corporation

jlewi@…2615…

From: Jeremy Lewi [mailto:jlewi@…2615…]
Sent: Friday, September 17, 2010 17:38

Is there a way to get the size of the bounding box for the axes which includes the axes labels and tick marks? It looks like Axes.get_position/set_position refers to the inner position (i.e the actual plot area).

Perhaps you could use the get_tightbbox() method possessed by Figure and Axes instances, although you need to tell it what renderer to use. If you’ve already drawn the figure in a GUI window, the method employed by FigureCanvasBase.print_figure in backend_bases.py might work:

fig = plt.gcf()

bbox = fig.get_tightbbox(fig._cachedRenderer)

You can then get the measurements using such properties and methods as these:

···
left, bottom, width, height = bbox.bounds
left, bottom, right, top = bbox.get_points().flatten()