Inset axes anchored to specific points in data coordinates?

两盒软妹~` 提交于 2019-12-08 21:21:49

问题


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, i.e. allow me to specify an arbitrary anchor point in data coordinates.

Any ideas?


回答1:


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 .



来源:https://stackoverflow.com/questions/19335900/inset-axes-anchored-to-specific-points-in-data-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!