插入轴锚定到数据坐标中的特定点? [英] Inset axes anchored to specific points in data coordinates?

查看:52
本文介绍了插入轴锚定到数据坐标中的特定点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在一组父轴上叠加多个插入轴,如下所示:

理想情况下,我希望将每组插入轴的锚点固定在数据坐标中,但要使轴的x,y范围随图形大小而不是数据的大小进行缩放.

例如,如果我放大父轴中的一个区域,我希望插入轴的位置与绘制在父轴中的数据一起移动,但它们的面积和纵横比保持不变相同的.我正在寻找的确切行为类似于绘图标记或 matplotlib.Annotation 实例.但是,我会满足于仅能够在数据坐标中设置轴的范围.

我知道我可以将 rect 参数传递给 axes() 以指定标准化 figure 坐标中的位置和范围.但是,我需要将轴固定到 data 坐标中的特定点.

我也尝试过这样做:

from matplotlib import pyplot as pp图,parent_ax = pp.subplots(1,1)parent_ax.set_xlim(0,1)parent_ax.set_ylim(0,1)# 数据坐标中所需的轴边界框矩形 = (0.1,0.2,0.2,0.3)child_ax =轴数(rect)#将转换应用于父轴的数据坐标child_ax.set_transform(parent_ax.transData)

这没有达到预期的效果(我的子轴的 x,y 限制现在与父轴的限制耦合,这是我不想要的,并且它的位置仍然不在数据坐标中).

我还查看了此处的各种示例,但没有其中一些似乎完全符合我的要求,即允许我在数据坐标中指定任意锚点.

有什么想法吗?

解决方案

将插入轴另存为图像,然后将其插入较大的图中.请参阅将小照片/图像添加到Matplotlib/Python中的一个大图.

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?

解决方案

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 .

这篇关于插入轴锚定到数据坐标中的特定点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆