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 ca10a34

Browse filesBrowse files
committed
Merge pull request #3861 from maxalbert/fix_get_window_extent
Added missing implementation of get_window_extent for AxisImage and test (fixes #2980).
2 parents df3530d + 87bac9d commit ca10a34
Copy full SHA for ca10a34

File tree

Expand file treeCollapse file tree

2 files changed

+27
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-0
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ def __init__(self, ax,
574574
**kwargs
575575
)
576576

577+
def get_window_extent(self, renderer=None):
578+
x0, x1, y0, y1 = self._extent
579+
bbox = Bbox.from_extents([x0, y0, x1, y1])
580+
return bbox.transformed(self.axes.transData)
581+
577582
def make_image(self, magnification=1.0):
578583
if self._A is None:
579584
raise RuntimeError('You must first set the image'

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,28 @@ def test_bbox_image_inverted():
335335
axes.add_artist(bbox_im)
336336

337337

338+
@cleanup
339+
def test_get_window_extent_for_AxisImage():
340+
# Create a figure of known size (1000x1000 pixels), place an image
341+
# object at a given location and check that get_window_extent()
342+
# returns the correct bounding box values (in pixels).
343+
344+
im = np.array([[0.25, 0.75, 1.0, 0.75], [0.1, 0.65, 0.5, 0.4], \
345+
[0.6, 0.3, 0.0, 0.2], [0.7, 0.9, 0.4, 0.6]])
346+
fig = plt.figure(figsize=(10, 10), dpi=100)
347+
ax = plt.subplot()
348+
ax.set_position([0, 0, 1, 1])
349+
ax.set_xlim(0, 1)
350+
ax.set_ylim(0, 1)
351+
im_obj = ax.imshow(im, extent=[0.4, 0.7, 0.2, 0.9], interpolation='nearest')
352+
353+
fig.canvas.draw()
354+
renderer = fig.canvas.renderer
355+
im_bbox = im_obj.get_window_extent(renderer)
356+
357+
assert_array_equal(im_bbox.get_points(), [[400, 200], [700, 900]])
358+
359+
338360
if __name__=='__main__':
339361
import nose
340362
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

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