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

Skip to content

Added missing implementation of get_window_extent for AxisImage and test (fixes #2980). #3861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ def __init__(self, ax,
**kwargs
)

def get_window_extent(self, renderer=None):
x0, x1, y0, y1 = self._extent
bbox = Bbox.from_extents([x0, y0, x1, y1])
return bbox.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.2, 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, 200], [700, 900]])


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