matplotlib: when using append_axes, how can I indicate the axes I want to add the subpanel to?
Asked Answered
B

1

10

I've been looking at the example "scatter hist" in the Matplotlib gallery.

At the moment the x/y subplots are at the top and on the right respectively, i.e.:

divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

However, if I change the subplot locations to:

divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

i.e. move the x subpanel to the bottom, then append_axes adds the y subplot to the right of the x subplot, rather than the right of the scatter plot. (I'd upload the image but I don't have a high enough reputation yet to post images... grrr)!

How can I tell append_axes that I want to append the y subplot to the right of the "main axes" containing the scatter plot? I'm guessing that I need to either specify the object axScatter again somewhere (though I thought that's what divider = make_axes_locatable(axScatter) was for?!) or I'm guessing that divider has set up a grid in the window panel and I need to tell append_axes which cell contains the main axes.

Thanks,

Alex

Burble answered 5/11, 2011 at 13:58 Comment(2)
I know that in the above case it will work if I simply switch around the divider.append_axes("top"...) and divider.append_axes("right"...) calls, but what about when I want to put subplots on the "bottom" and on the "left", when whichever way round I call append_axes, the subplots are still attached to the incorrect axes?!?Burble
I tried this but found no solution. seems like a bug.Knowall
K
2

The order in which you create axHisty and axHistx appears to matter. If you switch the order of the last two statements then you can get the desired effect:

divider = make_axes_locatable(axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1,  sharey=axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)

This sure stinks like a bug.

Kathiekathleen answered 6/7, 2012 at 19:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.