1

I am trying to plot a zoom plot inside the main 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: enter image description here

3
  • 2
    You should post a minimal reproducible example. Where is this code originally from? What is the shape of your DataFrame? Commented Apr 27, 2020 at 13:32
  • @Alex I updated my code with reproducable example. Thanks. Commented Apr 27, 2020 at 13:45
  • Useful to know the term for this is 'inset plot' (not 'subplot'). Specifically 'zoomed inset plot' Commented Oct 17, 2020 at 20:23

1 Answer 1

3

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:
Inset plot

Crucially, the min/max of t[:len(r)] is 0/0.009 respectively. So it seems the xlim that you apply is what is making it seem like there is no "zoom"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.