Skip to content

Commit 0ffa48e

Browse files
committed
Add test
1 parent e5b5425 commit 0ffa48e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from mpl_toolkits.axes_grid1 import make_axes_locatable
1010
from mpl_toolkits.axes_grid1 import AxesGrid
11+
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset
12+
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
1113

1214
from matplotlib.colors import LogNorm
1315

@@ -72,6 +74,55 @@ def test_axesgrid_colorbar_log_smoketest():
7274
grid.cbar_axes[0].colorbar(im)
7375

7476

77+
@image_comparison(
78+
baseline_images=['inset_locator'], style='default', extensions=['png'],
79+
remove_text=True)
80+
def test_inset_locator():
81+
def get_demo_image():
82+
from matplotlib.cbook import get_sample_data
83+
import numpy as np
84+
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
85+
z = np.load(f)
86+
# z is a numpy array of 15x15
87+
return z, (-3, 4, -4, 3)
88+
89+
fig, ax = plt.subplots(figsize=[5, 4])
90+
91+
# prepare the demo image
92+
Z, extent = get_demo_image()
93+
Z2 = np.zeros([150, 150], dtype="d")
94+
ny, nx = Z.shape
95+
Z2[30:30 + ny, 30:30 + nx] = Z
96+
97+
# extent = [-3, 4, -4, 3]
98+
ax.imshow(Z2, extent=extent, interpolation="nearest",
99+
origin="lower")
100+
101+
axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
102+
axins.imshow(Z2, extent=extent, interpolation="nearest",
103+
origin="lower")
104+
105+
# sub region of the original image
106+
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
107+
axins.set_xlim(x1, x2)
108+
axins.set_ylim(y1, y2)
109+
110+
plt.xticks(visible=False)
111+
plt.yticks(visible=False)
112+
113+
# draw a bbox of the region of the inset axes in the parent axes and
114+
# connecting lines between the bbox and the inset axes area
115+
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5")
116+
117+
asb = AnchoredSizeBar(ax.transData,
118+
0.5,
119+
'0.5',
120+
loc=8,
121+
pad=0.1, borderpad=0.5, sep=5,
122+
frameon=False)
123+
ax.add_artist(asb)
124+
125+
75126
if __name__ == '__main__':
76127
import nose
77128
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)