Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c63f1c

Browse files
committed
TST: add inset axes test
1 parent 0d3425a commit 4c63f1c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def _plot_args_replacer(args, data):
7777
"supported due to ambiguity of arguments.\nUse "
7878
"multiple plotting calls instead.")
7979

80+
8081
class _inset_locator(object):
8182
"""
8283
Helper class to locate inset axes, used in `.Axes.inset_axes`.
@@ -535,8 +536,8 @@ def inset_rectangle(self, rect, inset_ax=None, transform=None,
535536
if not inset_ax is None:
536537
# want to connect the indicator to the rect....
537538

538-
pos = inset_ax.get_position() # this is in fig-fraction.
539-
coordsA='axes fraction'
539+
pos = inset_ax.get_position() # this is in fig-fraction.
540+
coordsA = 'axes fraction'
540541
connects = []
541542
xr = [rect[0], rect[0]+rect[2]]
542543
yr = [rect[1], rect[1]+rect[3]]

lib/matplotlib/tests/test_axes.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5702,3 +5702,37 @@ def test_empty_errorbar_legend():
57025702
def test_plot_columns_cycle_deprecation():
57035703
with pytest.warns(MatplotlibDeprecationWarning):
57045704
plt.plot(np.zeros((2, 2)), np.zeros((2, 3)))
5705+
5706+
5707+
def test_zoom_inset():
5708+
5709+
dx, dy = 0.05, 0.05
5710+
5711+
# generate 2 2d grids for the x & y bounds
5712+
y, x = np.mgrid[slice(1, 5 + dy, dy),
5713+
slice(1, 5 + dx, dx)]
5714+
z = np.sin(x)**10 + np.cos(10 + y*x) * np.cos(x)
5715+
5716+
fig, ax = plt.subplots()
5717+
ax.pcolormesh(x, y, z)
5718+
ax.set_aspect(1.)
5719+
ax.apply_aspect()
5720+
# we need to apply_aspect to make the drawing below work.
5721+
5722+
# Make the inset_axes... Position axes co-ordinates...
5723+
axin1 = ax.inset_axes([0.7, 0.7, 0.35, 0.35])
5724+
# redraw the data in the inset axes...
5725+
axin1.pcolormesh(x, y, z)
5726+
axin1.set_xlim([1.5, 2.15])
5727+
axin1.set_ylim([2, 2.5])
5728+
axin1.set_aspect(ax.get_aspect())
5729+
5730+
rec, connectors = ax.zoom_inset_rectangle(axin1)
5731+
fig.canvas.draw()
5732+
xx = np.array([[1.5, 2. ],
5733+
[2.15, 2.5 ]])
5734+
assert(np.all(rec.get_bbox().get_points() == xx))
5735+
xx = np.array([[0.6325 , 0.692308],
5736+
[0.8425 , 0.907692]])
5737+
np.testing.assert_allclose(axin1.get_position().get_points(),
5738+
xx, rtol=1e-4)

0 commit comments

Comments
 (0)