放大插图中不同的 x 和 y 比例,matplotlib [英] Different x and y scale in zoomed inset, matplotlib

查看:79
本文介绍了放大插图中不同的 x 和 y 比例,matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用matplotlib制作插图.目前我有类似的最后一个答案如何放大图像的一部分并插入到 matplotlib 中的同一图中

I am trying to make an inset plot using matplotlib. Currently I have something like the last answer in How to zoomed a portion of image and insert in the same plot in matplotlib

那里有一个确定缩放系数的参数.但是,我想在x和y轴之间更改比例,即我想在x轴上放大更多.(因此,在示例中,正方形将被映射到插图中的矩形).

There is a parameter there which determines the zoom factor. However, I want to change the scale between the x and y axes, ie I want to zoom in more on the xaxis. (so in the example, the square would be mapped to a rectangle under the inset map).

我如何实现这一目标?

这是一个有效的示例:

import pylab as pl
import numpy as np
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

x=np.linspace(0,1,100)
y=x**2

ax=pl.subplot(1,1,1)
ax.plot(x,y)

axins = zoomed_inset_axes(ax, 1, loc=2,bbox_to_anchor=(0.2, 0.55),bbox_transform=ax.figure.transFigure) # zoom = 6



axins.plot(x,y)

x1, x2= .4, .6
y1,y2 = x1**2,x2**2
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
mark_inset(ax, axins, loc1=1, loc2=3, fc="none", ec="0.5")
pl.show()

所以我想要做的是能够分别改变插图的宽度和高度,而不改变插图的 x 和 y 范围.

So what I want to do is to be able to change the width and height of the inset separately, without changing the x and y ranges of the inset.

推荐答案

对于正在寻找这个的其他人,事实证明这可以通过使用 inset_axes() 方法而不是 来完成zoomed_inset_axes().

For anyone else looking for this, it turns out this can be accomplished by using the inset_axes() method rather than zoomed_inset_axes().

例如:

axins = inset_axes(ax, 1,1 , loc=2,bbox_to_anchor=(0.2, 0.55),bbox_transform=ax.figure.transFigure) # no zoom

1,1 部分分别设置插图的宽度和高度.在此之后,使用 xlim()ylim() 设置轴的范围,而不更改插入框的大小或形状.

The 1,1 section sets the width and height of the inset, respectively. After this, use the xlim() and ylim() to set the extents of the axes without changing the size or shape of the inset box.

这篇关于放大插图中不同的 x 和 y 比例,matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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