Created
October 7, 2014 05:37
-
-
Save nicoguaro/b91c4bf7a8815676bfb9 to your computer and use it in GitHub Desktop.
An example of a zoom in a simple plot using `zoomed_inset_axes`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes | |
from mpl_toolkits.axes_grid1.inset_locator import mark_inset | |
import numpy as np | |
fig, ax = plt.subplots() | |
n = 1000 | |
x = np.linspace(-6.3, 6.3, n) | |
y = np.sin(x) + 0.1*np.random.rand(n) | |
ax.plot(x, y) | |
axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6 | |
axins.plot(x, y) | |
axins.set_xlim(0, 0.2) # Limit the region for zoom | |
axins.set_ylim(0, 0.2) | |
plt.xticks(visible=False) # Not present ticks | |
plt.yticks(visible=False) | |
# | |
## draw a bbox of the region of the inset axes in the parent axes and | |
## connecting lines between the bbox and the inset axes area | |
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5") | |
plt.draw() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment