Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added missing implementation of get_window_extent for AxisImage and t…
…est (fixes #2980).
  • Loading branch information
maxalbert committed Nov 29, 2014
commit 488eb61e5208454d05a68f952644ec1c7d1f6342
4 changes: 4 additions & 0 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ def __init__(self, ax,
**kwargs
)

def get_window_extent(self, renderer=None):
x0, x1, y0, y1 = self._extent
return Bbox.from_extents([x0, y0, x1, y1]).transformed(self.axes.transData)

def make_image(self, magnification=1.0):
if self._A is None:
raise RuntimeError('You must first set the image'
Expand Down
22 changes: 22 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ def test_bbox_image_inverted():
axes.add_artist(bbox_im)


@cleanup
def test_get_window_extent_for_AxisImage():
# Create a figure of known size (1000x1000 pixels), place an image
# object at a given location and check that get_window_extent()
# returns the correct bounding box values (in pixels).

im = np.array([[0.25, 0.75, 1.0, 0.75], [0.1, 0.65, 0.5, 0.4], \
[0.6, 0.3, 0.0, 0.2], [0.7, 0.9, 0.4, 0.6]])
fig = plt.figure(figsize=(10, 10), dpi=100)
ax = plt.subplot()
ax.set_position([0, 0, 1, 1])
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
im_obj = ax.imshow(im, extent=[0.4, 0.7, 0.22, 0.9], interpolation='nearest')

fig.canvas.draw()
renderer = fig.canvas.renderer
im_bbox = im_obj.get_window_extent(renderer)

assert_array_equal(im_bbox.get_points(), [[400, 220], [700, 900]])


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)