-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
How to easily set the location and size of a sub_axes? #8986
Comments
but it is a bit roundabout... |
This works without a import cartopy.crs as ccrs
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
box = mpl.transforms.Bbox.from_bounds(0.8, 0.8, 0.2, 0.2)
ax2 = fig.add_axes(fig.transFigure.inverted().transform_bbox(ax.transAxes.transform_bbox(box)), projection=ccrs.PlateCarree()) I tried to give a miminal example, sorry for the |
I think cartopy returns a geoaxes object which is a superset of axes. Not sure, but maybe this is a cartopy question/issue. I can't test right now if this is an issue with vanilla matplotlib projections, nor do I understand exactly what they do.
… On Aug 5, 2017, at 06:33, WANG Aiyong ***@***.***> wrote:
This works without a projection. But with a projection is doesn't. Like following:
import cartopy.crs as ccrs
fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
box = mpl.transforms.Bbox.from_bounds(0.8, 0.8, 0.2, 0.2)
ax2 = fig.add_axes(fig.transFigure.inverted().transform_bbox(ax.transAxes.transform_bbox(box)), projection=ccrs.PlateCarree())
I got this:
I tried to give a miminal example, sorry for the cartopy import.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@jklymak Thanks. |
Again don't have a computer right now so I don't know but I suspect the issue is that the parent axis gets redrawn by the projection but the child axis has no way to know this and gets put in the location it would be at if the parent axis wasn't a projection.
I've been playing with a geometry manager that should let you line axes up, but only if the new axes positions get set during the projection. I'm not really familiar w the projection code so again, id bug the cartopy folks. Or set the child position by hand.
Cheers. Jody.
…Sent from my iPhone
On Aug 5, 2017, at 16:25, WANG Aiyong ***@***.***> wrote:
@jklymak Thanks.
Is there a way I can anchor the top right point ([1.0, 1.0]) of ax2 at the top right corner of ax1 ([1.0, 1.0])?
Then the position or size of ax2 won't matter that much.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
The plot you obtained is "correct" in that those really are the limits of the axes space, but Cartopy has turned off the axis spines and ticks and is drawing its own boundary which is not necessarily "full" (this is how you can get complicated maps like Interrupted Goode Homolosine). If you want to do something based on that boundary, you can do something like call |
One wonders if cartopy could return the extent of the spines somehow. I've been thinking about layout management and lining up spines is a pretty important part of layout. |
I may have figured out an answer. For someone who may run into the same problem, here is a working solution. |
The problem comes from me drawwing a map via cartopy. I want to add a little sub_axes on the lower_right corner of the main axes. But it seems hard to set the location and size of the sub_axes.
The first thing I tried was
fig.add_axes()
. But it doesn't accepttransform
args, while the document says it should. Without thetransform
args, the location (left, bottom) and size (width, height) wasn't on the transform ofax
.The second I tried was
inset_axes
, which was very easy to use. But it doesn't acceptprojection
args.I may get what I want by
ax.get_position()
, the set the position according it.The text was updated successfully, but these errors were encountered: