-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Handling different projections in axes_grid1.AxisDivider #9707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Whats wrong with: fig = plt.figure(figsize=(6,12)) # tall figure
ax = fig.add_subplot(1, 2, 1, projection='polar')
im = ax.pcolormesh(t, r, c.T)
fig.colorbar(im, ax=ax, shrink=0.2) If you want to get fancy, you can figure out the shrink... I'm actually surprised that there is no way to set the projection except via |
Hi jklymak, there is nothing wrong with shrink. But still the problem is how to figure out the shrink, which I think I think |
Very true. I generated a lot of map plots (which are usually rectangular) with Cartopy, and the axes_grid1 doesn't work, probably due to the lack of support of "map_projection." I ended up tweaking 'shrink' argument. By the way, you can actually set projection for a bunch of plots at once using |
I'm not a huge fan of The problem, as it often is, is interactivity. Yes, I think its possible to make the colorbar match the size of the parent axes using the aspect ratio of the plot as it currently is set. But if the user changes the aspect ratio of the plot (by adjusting the x or y-lims or zooming) then does the colorbar change size? That sort of interactivity isn't impossible, but starts to make the code pretty complicated. Personally, I'd rather someone composing a figure just eyeball a good-looking colorbar shrink and aspect, rather than introduce a slew of hooks where the axis for the colorbar gets adjusted on the fly. But if someone wants to work on it, I'm sure a PR would be welcomed. |
@jklymak This seems like the sort of problem that the constraints based layout should be able to address. |
@tacaswell Yes, I think so. Its been a while (;-)) so I'd have to check and see what it does already. Part of the impetus for #9855 was for the constrained layout to know how big the axes wanted to be. The question will be (once we get there) is what the default should be (shrink is proportional to original or modified Axes position) and how to implement choosing. |
The gist link above is dead, so let's just move the full discussion to #3286, as I think(?) all the relevant info is over there. |
Hi, all. There have been some discussions about using
axes_grid1.AxisDivider
with polar projected images to make axis for a colorbar with proper height/width (E.g., my comment on an old issue #3286 and ). It appears to me that there is a bug inaxes_grid1.axes_size.AxisX
andAxisY
that assume rectangular projection.I changed

mpl_toolkits.axes_grid1.axes_size.py
a little to support polar projection (almost) properly. Please see https://gist.github.com/jimgreen/839f43897e9c1d54f6fb4b890a93ee1b for a working example.The result after fixing is of the left, and the simple call to plt.colorbar() is on the right:
I wonder if this the right thing to do? And, perhaps we need to support other projections, too?
PS:
axes_class=matplotlib.axes._axes.Axes
individer.append_axes
to get the proper axis forcolorbar
. Otherwise the returned ax would have same projection as the input ax, which is polar.GridSpec
is also nice (see https://stackoverflow.com/questions/24894625/adding-a-colorbar-to-a-pcolormesh-with-polar-projection). But it (to me) is a very different solution to theaxes_grid1
way.The text was updated successfully, but these errors were encountered: