简体   繁体   中英

Inset axes anchored to specific points in data coordinates?

I'd like to be able to overlay multiple inset axes on top of a set of parent axes, something like this:

在此输入图像描述

Ideally, I'd like the anchor point of each set of inset axes to be fixed in data coordinates, but for the x,y extent of the axes to scale with figure size rather than the scale of the data.

For example, if I zoomed in on a region in the parent axes, I'd want the positions of the inset axes to move together with the data plotted in the parent axes, but for their areas and aspect ratios to stay the same. The exact behaviour I'm looking for is something similar to a plot marker or a matplotlib.Annotation instance. However, I'd settle for just being able to set the extent of the axes in data coordinates.

I'm aware that I can pass the rect argument to axes() to specify the position and extent in normalized figure coordinates. However, I need my axes to be anchored to specific points in data coordinates.

I've also tried doing something like this:

from matplotlib import pyplot as pp

fig,parent_ax = pp.subplots(1,1)
parent_ax.set_xlim(0,1)
parent_ax.set_ylim(0,1)

# desired axis bounding box in data coordinates
rect = (0.1,0.2,0.2,0.3)

child_ax = axes(rect)

# apply transformation to data coordinates of parent axis
child_ax.set_transform(parent_ax.transData)

which doesn't have the desired effect (the x,y limits of my child axis are now coupled to those of the parent axis, which I don't want, and its position is still not in data coordinates).

I've also looked at the various examples here , but none of them seem to do quite what I'm looking for, ie allow me to specify an arbitrary anchor point in data coordinates.

Any ideas?

Save the inset axes as images and then insert them in the larger figure. See Adding a small photo/image to a large graph in Matplotlib/Python .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM