matplotlib zoomed plot window inside a main plot?

matplotlib zoomed plot window inside a main plot?

我正在尝试在主图中绘制缩放图。我在 运行 代码和绘图方面取得了成功。但是没有放大。

我的代码:

# 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()

当前输出:

所以这段代码:

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)

产生:

重要的是,t[:len(r)]min/max 分别是 0/0.009。因此,您应用的 xlim 似乎使它看起来好像没有 "zoom"