Skip to content

How to easily set the location and size of a sub_axes? #8986

@gepcel

Description

@gepcel

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 accept transform args, while the document says it should. Without the transform args, the location (left, bottom) and size (width, height) wasn't on the transform of ax.

import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax2 = fig.add_axes([0.8, 0, 0.2, 0.2], transform=ax.transAxes, projection='rectilinear') 

The second I tried was inset_axes, which was very easy to use. But it doesn't accept projection args.

from mpl_toolkits.axes_grid.inset_locator import inset_axes
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# The following line doesn't work
ax2 = inset_axes(ax, width='20%', height='20%', axes_kwargs={'projection': 'rectilinear'})
# Doesn't work neither:
ax2 = inset_axes(ax, width='20%', height='20%', projection='rectilinear')

I may get what I want by ax.get_position(), the set the position according it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions