Related to: plotting autoscaled subplots with fixed limits in matplotlib
I would like to make a set of subplots that are all on the same scale, using the subplots new compact style, as in http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots and have them be square.
I tried:
fig, axes = subplots(numplots, 1, sharex=True, sharey=True, adjustable='box', aspect='equal')
But I found that these keyword arguments are not implemented in the subplots wrapper. What’s the way to do it?
To reiterate, the goal is simply to have shared axes, so that all the data are on the same scale, and have the plots be square.
Just use
adjustable='box-forced'instead ofadjustable='box'.As @cronos mentions, you can pass it in using the
subplot_kwkwarg (additional keyword arguments tosubplotsare passed on to theFigurenot theAxes, thus the need forsubplot_kw).Instead, I’m going to use
setp, which basically just doesfor item in sequence: item.set(**kwargs). (All matplotlib artists have asetmethod that can be used similar to matlab’sset.)Which one is the “better” approach will depend on what you’re doing. A lot of people would argue that
setpis very “unpythonic”, but I don’t see the problem with it.As a quick example:
I forget the reason for the two different adjustable box styles, at the moment. I remember that I found it really confusing the first time I came across it, and I dug through the code and there was some obvious reason for it… I can’t remember what that reason was at the moment, though.