Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 082b8a6

Browse filesBrowse files
committed
TST: add inset axes test
1 parent 0d3425a commit 082b8a6
Copy full SHA for 082b8a6

File tree

Expand file treeCollapse file tree

4 files changed

+40
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+40
-4
lines changed

‎examples/mplot3d/lines3d.py

Copy file name to clipboardExpand all lines: examples/mplot3d/lines3d.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
x = r * np.sin(theta)
2424
y = r * np.cos(theta)
2525

26-
ax.plot(x, y, z, label='parametric curve')
26+
l = ax.plot(x, y, z, label='parametric curve')
2727
ax.legend()
2828

2929
plt.show()

‎examples/subplots_axes_and_figures/zoom_inset_axes.py

Copy file name to clipboardExpand all lines: examples/subplots_axes_and_figures/zoom_inset_axes.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import matplotlib.pyplot as plt
1111
import numpy as np
1212

13+
1314
def get_demo_image():
1415
from matplotlib.cbook import get_sample_data
1516
import numpy as np

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+4-3Lines changed: 4 additions & 3 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`.
@@ -532,11 +533,11 @@ def inset_rectangle(self, rect, inset_ax=None, transform=None,
532533
zorder=zorder, label=label, transform=transform, **kwargs)
533534
self.add_patch(rectpatch)
534535

535-
if not inset_ax is None:
536+
if inset_ax is not 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+34Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.