Inset zoom of matplotlib plot is marked on the wrong corners

Viewed 4328

I want to plot a curve and zoom and have an inset which shows a zoom of a specific part of my plot. This is my code, which partly realizes this:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

fig, ax = plt.subplots()
axins = inset_axes(ax, 1,1 , loc=2, bbox_to_anchor=(.08, 0.35),bbox_transform=axfft.figure.transFigure)

x = np.linspace(0, 3, 100)
y = x**2
ax.plot(x, y)
axins.plot(x, y)

x1, x2, y1, y2 = 1, 2, .5, 4.5 # specify the limits
axins.set_xlim(x1, x2) # apply the x-limits
axins.set_ylim(y1, y2) # apply the y-limits

plt.xticks(visible=False)
plt.yticks(visible=False)

mark_inset(ax, axins, loc1=2, loc2=3, fc="none", ec="0.5")

This is the output it produces:

enter image description here

MY QUESTION:

How can I make mark_inset put the lines on the right corners of the inset instead of the left ones? The way it currently is, the indicator lines cross my inset and I do not want that.

1 Answers
Related