Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11026 from jklymak/enh-axes-add-axes
ENH add an inset_axes to the axes class
- Loading branch information
Showing
7 changed files
with
373 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
====================== | ||
Zoom region inset axes | ||
====================== | ||
Example of an inset axes and a rectangle showing where the zoom is located. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
def get_demo_image(): | ||
from matplotlib.cbook import get_sample_data | ||
import numpy as np | ||
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False) | ||
z = np.load(f) | ||
# z is a numpy array of 15x15 | ||
return z, (-3, 4, -4, 3) | ||
|
||
fig, ax = plt.subplots(figsize=[5, 4]) | ||
|
||
# make data | ||
Z, extent = get_demo_image() | ||
Z2 = np.zeros([150, 150], dtype="d") | ||
ny, nx = Z.shape | ||
Z2[30:30 + ny, 30:30 + nx] = Z | ||
|
||
ax.imshow(Z2, extent=extent, interpolation="nearest", | ||
origin="lower") | ||
|
||
# inset axes.... | ||
axins = ax.inset_axes([0.5, 0.5, 0.47, 0.47]) | ||
axins.imshow(Z2, extent=extent, interpolation="nearest", | ||
origin="lower") | ||
# sub region of the original image | ||
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9 | ||
axins.set_xlim(x1, x2) | ||
axins.set_ylim(y1, y2) | ||
axins.set_xticklabels('') | ||
axins.set_yticklabels('') | ||
|
||
ax.indicate_inset_zoom(axins) | ||
|
||
plt.show() | ||
|
||
############################################################################# | ||
# | ||
# ------------ | ||
# | ||
# References | ||
# """""""""" | ||
# | ||
# The use of the following functions and methods is shown in this example: | ||
|
||
import matplotlib | ||
matplotlib.axes.Axes.inset_axes | ||
matplotlib.axes.Axes.indicate_inset_zoom | ||
matplotlib.axes.Axes.imshow |
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
Oops, something went wrong.