简体   繁体   English

matplotlib 放大 plot window 在主 Z32FA6E1B78A9D4028953E60564A2AA4Z 内

[英]matplotlib zoomed plot window inside a main plot?

I am trying to plot a zoom plot inside the main plot.我正在尝试 plot 放大 plot 里面的主要 plot。 I was successful in running the code and getting the plots.我成功地运行了代码并获得了绘图。 But there was no zoom-in.但是没有放大。

My code:我的代码:

# create some data to use for the plot
dt = 0.001
t = np.arange(0.0, 10.0, dt)
r = np.exp(-t[:10]/0.05)               # impulse response
x = np.random.randn(len(t))
s = np.convolve(x, r)[:len(x)]*dt  # colored noise

# the main axes is subplot(111) by default
plt.plot(t, s)

# this is another inset axes over the main axes
a = plt.axes([0.2, 0.6, .2, .2])
plt.plot(t[:len(r)], r)
plt.xlim(0, 0.2)
plt.xticks([])
plt.yticks([])
plt.show()

Present output:目前output: 在此处输入图像描述

So this code:所以这段代码:

dt = 0.001
t = np.arange(0.0, 10.0, dt)
r = np.exp(-t[:10]/0.05)
x = np.random.randn(len(t))
s = np.convolve(x, r)[:len(x)] * dt

fig, ax = plt.subplots()
ax.plot(t, s)

inset_ax = ax.inset_axes([0.2, 0.6, 0.2, 0.2])
inset_ax.plot(t[:len(r)], r)

Produces:生产:
插图

Crucially, the min / max of t[:len(r)] is 0 / 0.009 respectively.至关重要的是, t[:len(r)]min / max分别为0 / 0.009 So it seems the xlim that you apply is what is making it seem like there is no "zoom"因此,您应用的xlim似乎是使它看起来没有“缩放”的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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