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 d9258d3

Browse filesBrowse files
jklymaktacaswell
authored andcommitted
Merge pull request #10756 from AlexCav/iss-8120-bugfix
Fixes png showing inconsistent inset_axes position Conflicts: lib/mpl_toolkits/axes_grid1/inset_locator.py - keep non-superified version
1 parent 7a25941 commit d9258d3
Copy full SHA for d9258d3

File tree

Expand file treeCollapse file tree

3 files changed

+82
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+82
-6
lines changed

‎lib/mpl_toolkits/axes_grid1/inset_locator.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/inset_locator.py
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,23 @@ def get_extent(self, renderer):
105105
dpi = renderer.points_to_pixels(72.)
106106

107107
r, a = self.x_size.get_size(renderer)
108-
width = w*r + a*dpi
108+
width = w * r + a * dpi
109109

110110
r, a = self.y_size.get_size(renderer)
111-
height = h*r + a*dpi
111+
height = h * r + a * dpi
112112
xd, yd = 0, 0
113113

114114
fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
115115
pad = self.pad * fontsize
116116

117-
return width+2*pad, height+2*pad, xd+pad, yd+pad
117+
return width + 2 * pad, height + 2 * pad, xd + pad, yd + pad
118118

119119

120120
class AnchoredZoomLocator(AnchoredLocatorBase):
121121
def __init__(self, parent_axes, zoom, loc,
122122
borderpad=0.5,
123123
bbox_to_anchor=None,
124124
bbox_transform=None):
125-
126125
self.parent_axes = parent_axes
127126
self.zoom = zoom
128127

@@ -141,7 +140,7 @@ def get_extent(self, renderer):
141140
fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
142141
pad = self.pad * fontsize
143142

144-
return abs(w*self.zoom)+2*pad, abs(h*self.zoom)+2*pad, pad, pad
143+
return abs(w * self.zoom) + 2 * pad, abs(h * self.zoom) + 2 * pad, pad, pad
145144

146145

147146
class BboxPatch(Patch):
@@ -184,6 +183,7 @@ def get_path(self):
184183
Path.CLOSEPOLY]
185184

186185
return Path(verts, codes)
186+
187187
get_path.__doc__ = Patch.get_path.__doc__
188188

189189

@@ -318,6 +318,7 @@ def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs):
318318
def get_path(self):
319319
return self.connect_bbox(self.bbox1, self.bbox2,
320320
self.loc1, self.loc2)
321+
321322
get_path.__doc__ = Patch.get_path.__doc__
322323

323324

@@ -373,6 +374,7 @@ def get_path(self):
373374
list(path2.vertices) +
374375
[path1.vertices[0]])
375376
return Path(path_merged)
377+
376378
get_path.__doc__ = BboxConnector.get_path.__doc__
377379

378380

@@ -453,6 +455,9 @@ def inset_axes(parent_axes, width, height, loc=1,
453455
if bbox_to_anchor is None:
454456
bbox_to_anchor = parent_axes.bbox
455457

458+
if bbox_transform is None:
459+
bbox_transform = parent_axes.transAxes
460+
456461
axes_locator = AnchoredSizeLocator(bbox_to_anchor,
457462
width, height,
458463
loc=loc,
Loading

‎lib/mpl_toolkits/tests/test_axes_grid1.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_axes_grid1.py
+72-1Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
from mpl_toolkits.axes_grid1 import host_subplot
1010
from mpl_toolkits.axes_grid1 import make_axes_locatable
1111
from mpl_toolkits.axes_grid1 import AxesGrid
12-
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset
12+
from mpl_toolkits.axes_grid1.inset_locator import (
13+
zoomed_inset_axes,
14+
mark_inset,
15+
inset_axes
16+
)
1317
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
1418

1519
from matplotlib.colors import LogNorm
@@ -155,6 +159,73 @@ def get_demo_image():
155159
ax.add_artist(asb)
156160

157161

162+
@image_comparison(
163+
baseline_images=['inset_axes'], style='default', extensions=['png'],
164+
remove_text=True)
165+
def test_inset_axes():
166+
def get_demo_image():
167+
from matplotlib.cbook import get_sample_data
168+
import numpy as np
169+
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
170+
z = np.load(f)
171+
# z is a numpy array of 15x15
172+
return z, (-3, 4, -4, 3)
173+
174+
fig, ax = plt.subplots(figsize=[5, 4])
175+
176+
# prepare the demo image
177+
Z, extent = get_demo_image()
178+
Z2 = np.zeros([150, 150], dtype="d")
179+
ny, nx = Z.shape
180+
Z2[30:30 + ny, 30:30 + nx] = Z
181+
182+
# extent = [-3, 4, -4, 3]
183+
ax.imshow(Z2, extent=extent, interpolation="nearest",
184+
origin="lower")
185+
186+
# creating our inset axes without a bbox_transform parameter
187+
axins = inset_axes(ax, width=1., height=1., bbox_to_anchor=(1, 1))
188+
189+
axins.imshow(Z2, extent=extent, interpolation="nearest",
190+
origin="lower")
191+
axins.yaxis.get_major_locator().set_params(nbins=7)
192+
axins.xaxis.get_major_locator().set_params(nbins=7)
193+
# sub region of the original image
194+
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
195+
axins.set_xlim(x1, x2)
196+
axins.set_ylim(y1, y2)
197+
198+
plt.xticks(visible=False)
199+
plt.yticks(visible=False)
200+
201+
# draw a bbox of the region of the inset axes in the parent axes and
202+
# connecting lines between the bbox and the inset axes area
203+
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5")
204+
205+
asb = AnchoredSizeBar(ax.transData,
206+
0.5,
207+
'0.5',
208+
loc=8,
209+
pad=0.1, borderpad=0.5, sep=5,
210+
frameon=False)
211+
ax.add_artist(asb)
212+
213+
214+
def test_inset_axes_without_transform_should_use_parent_axes():
215+
# creating our figure
216+
fig = plt.figure(dpi=150)
217+
218+
# gca method gets current axes of the figure
219+
ax = plt.gca()
220+
ax.plot([0.0, 0.25, 0.50, 1.0], [0.1, 0.2, 0.4, 0.9], color='b')
221+
222+
# creating our inset_axes. without a bbox_transform parameter
223+
ax_ins = inset_axes(ax, width=1., height=1., bbox_to_anchor=(1, 1))
224+
ax_ins.plot([0.0, 0.25, 0.50, 1.0], [0.9, 0.4, 0.2, 0.1], color='r')
225+
226+
assert ax.transAxes == ax_ins.transAxes
227+
228+
158229
@image_comparison(baseline_images=['zoomed_axes',
159230
'inverted_zoomed_axes'],
160231
extensions=['png'])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.