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:
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.
mark_inset
always uses the same corners on both, the inset and the location rectangle. You can set those with the loc1
and loc2
argument.
To prevent the lines crossing the axes, you may use
mark_inset(ax, axins, loc1=1, loc2=3, fc="none", ec="0.5")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With