Also interesting is if you pass ax[0, 0], space is stolen from the top-left, but if you pass [ax[0, 0]], space is stolen from the right. I know these are supposed to be different, but not that different.
[ax[0, 0], ax[1, 1]] steals from the right only, though I'd expect some kind of warning or even an error.
Thanks, @QuLogic I meant to report that too but forgot.
The behaviour for [ax[0, 0], ax[1, 1]] seems reasonable to me; "insert a colorbar with vertical extent bounded by the top and bottom of both axes; and to the right of the rightmost axes"
I agree that its inconsistent between constrained_layout=True and constrained_layout=False. Its possible I can add this functionality to the constrained_layout algorithm, but I'm not sure.
In the meantime, the way to do what you want is indeed a bit longer. It also loses the idea that the subplots have the same size. OTOH, if you are adding a colorbar to one column, but not the second, my guess would be they contain different data types.
OTOH, if you are adding a colorbar to one column, but not the second, my guess would be they contain different data types.
Yes, different data types but on the same x,y grid. Practically, the two axes on the right could have a shared colorbar or one colorbar each and that would make the axes the same size which would be fine. My example was over-simplified. The below is what I'm aiming for with the big colorbar for the 2 panels on the left.
import matplotlib.pyplot as plt
import numpy as np
f, ax = plt.subplots(2,2, constrained_layout=True)
data = np.random.randn(10, 10)
for aa in ax.flat:
mappable = aa.pcolormesh(data)
f.colorbar(mappable, ax=ax[:, 0])
f.colorbar(mappable, ax=ax[0, 1])
f.colorbar(mappable, ax=ax[1, 1])
Activity
QuLogic commented on Jul 12, 2018
Also interesting is if you pass ax[0, 0], space is stolen from the top-left, but if you pass [ax[0, 0]], space is stolen from the right. I know these are supposed to be different, but not that different.
[ax[0, 0], ax[1, 1]] steals from the right only, though I'd expect some kind of warning or even an error.
dcherian commented on Jul 12, 2018
Thanks, @QuLogic I meant to report that too but forgot.
The behaviour for [ax[0, 0], ax[1, 1]] seems reasonable to me; "insert a colorbar with vertical extent bounded by the top and bottom of both axes; and to the right of the rightmost axes"
jklymak commented on Jul 12, 2018
Colorbar either steals space from an axes or a GridSpec. If you specify multiple axes in the same GridSpec it steals from the whole GridSpec.
To get what you want, you need to make a nested GridSpec. See the docomplicated example in the tutorial.
jklymak commented on Jul 12, 2018
I agree that its inconsistent between constrained_layout=True and constrained_layout=False. Its possible I can add this functionality to the constrained_layout algorithm, but I'm not sure.
In the meantime, the way to do what you want is indeed a bit longer. It also loses the idea that the subplots have the same size. OTOH, if you are adding a colorbar to one column, but not the second, my guess would be they contain different data types.
jklymak commented on Jul 12, 2018
I think I can make this consistent, but milestoning 3.1 because there is a workaround and its a bit of an obscure use case.
dcherian commented on Jul 12, 2018
Yes, different data types but on the same x,y grid. Practically, the two axes on the right could have a shared colorbar or one colorbar each and that would make the axes the same size which would be fine. My example was over-simplified. The below is what I'm aiming for with the big colorbar for the 2 panels on the left.
import matplotlib.pyplot as plt import numpy as np f, ax = plt.subplots(2,2, constrained_layout=True) data = np.random.randn(10, 10) for aa in ax.flat: mappable = aa.pcolormesh(data) f.colorbar(mappable, ax=ax[:, 0]) f.colorbar(mappable, ax=ax[0, 1]) f.colorbar(mappable, ax=ax[1, 1])jklymak commented on Jul 12, 2018
PR, coming, but I need to write some tests and update the guide.
BTW< thanks for giving constrained_layout a try! Please report any other issues so I can keep polishing it...
dcherian commented on Jul 12, 2018
@jklymak This looks great! Thanks for all your hard work. It has certainly made life a whole lot easier.