Skip to content

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

Closed
liangwang0734 opened this issue Nov 6, 2017 · 7 comments
Closed

Handling different projections in axes_grid1.AxisDivider #9707

liangwang0734 opened this issue Nov 6, 2017 · 7 comments

Comments

@liangwang0734
Copy link

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 in axes_grid1.axes_size.AxisX and AxisY 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:
image

I wonder if this the right thing to do? And, perhaps we need to support other projections, too?

PS:

@jklymak
Copy link
Member

jklymak commented Nov 6, 2017

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 add_subplot.

@liangwang0734
Copy link
Author

Hi jklymak, there is nothing wrong with shrink. But still the problem is how to figure out the shrink, which I think axes_grid1.axes_size can do. Honestly, it should be not too hard to do without axes_grid1.axes_size.

I think fig.colorbar internally uses GridSpec, so perhaps just a different way to do it. But I still think axes_grid1.axes_size should handle different projections properly.

@tacaswell tacaswell added this to the v2.2 milestone Nov 7, 2017
@fischcheng
Copy link

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 f, axarr = plt.subplots(2, 2, subplot_kw=dict(projection='polar')). For me the issue is, I want different projections in different panels, so add_subplot seems to be the only way out... (and again shrink)

@jklymak
Copy link
Member

jklymak commented Nov 25, 2017

I'm not a huge fan of axes_grid1, so I think it'd be nice to see any functionality like this in fig.colorbar.

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.

@tacaswell
Copy link
Member

@jklymak This seems like the sort of problem that the constraints based layout should be able to address.

@jklymak
Copy link
Member

jklymak commented Nov 25, 2017

@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.

@anntzer
Copy link
Contributor

anntzer commented Dec 29, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants