0

I'm trying to get a plot done using Python.matplotlib in which I would add to a first plot a zoomed region in a box located in the lower right corner.

Looking at documentation and examples, I know that this is usually done using zoomed_inset_axes but it seems to only take one factor for zooming/dilating for both directions enter image description herewhen I'd like to dilate only along the y axis (looking at the attached picture it is easy to guess why). So I tried to give a bbox scaled as I would like but it doesn't seem to do the trick. Is there an axis transformation or a data operation that could help me?

The red arrows and box described the size I would like my box to take (more or less, I'll tune later of course).

Edit:

I've been playing with it a bit more and my problem seems to be that the two graphs, in the current state, do share the same y-axis scale.

Here is my code, by the way, should have been included in the first place:

ax = plt.gca()
axins = zoomed_inset_axes(ax, 1, loc=4)
axins.scatter(x,y, lw=0.1,c="#1B9E77",alpha=0.8)
x1, x2, y1, y2 = -75, 5200, -0.31, -0.18 #coordinates of the region I'm zooming in
axins.plot(N.linspace(x1,x2,100),[-0.25]*100,c="#EFD807",lw=3) #yellow line

axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
mark_inset(ax, axins, loc1=3, loc2=1, fc="none", ec="0.5")
Learning is a mess
  • 7,479
  • 7
  • 35
  • 71
  • 1
    They will share the same scale on both axis (I think) since your zoom factor is 1. That is, the second argument of `zoomed_inset_axes` is the `zoom` factor. – Greg Nov 06 '14 at 14:15
  • Yes, but it doesn't seem possible to pass different `zoom` factors for the x and y axis, that's what I'm trying to circumvent. – Learning is a mess Nov 06 '14 at 14:27

1 Answers1

3

An alternative method to zoomed_inset_axes is to do it 'manually'. I'm sure there are short comings to this method so if people know of them please comment. I by no means am suggesting this is the best method - just one I've seen about.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 100, 1000)
y = np.sin(x)

ax = plt.subplot(111)
ax.plot(x, y)
ax.set_ylim(-50, 10)

ax2 = plt.axes([0.2, 0.2, .6, .2])
ax2.plot(x, y)

mark_inset(ax, ax2, loc1=2, loc2=1, fc="none", ec="0.5")

plt.show()

enter image description here

This answer is adapted from this original SO post.

An altenative method is proposed in this SO post.

Community
  • 1
  • 1
Greg
  • 11,654
  • 3
  • 44
  • 50
  • Thank you for the input, indeed that would work, but I'm afraid that it won't be possible to add the `mark_inset` drawing the dashed lines, very eloquent in showing that we are zooming on the curve. I would have to add xticks and yticks to give the idea. – Learning is a mess Nov 06 '14 at 14:26