Closed
Description
I am finding that the get_window_extent method for an image object gives all zeros.
For example
import numpy as np
import matplotlib.pyplot as plt
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()
ax = plt.subplot()
ax.set_xlim(0,1)
ax.set_ylim(0,1)
im_obj = ax.imshow(im, extent = [0.25, 0.75, 0.25, 0.75], interpolation = 'nearest')
produces the following plot
Now I want to get the image size in display coordinates, so I do the following:
fig.canvas.draw()
renderer = fig.canvas.renderer
im_bbox = im_obj.get_window_extent(renderer)
The trouble is print im_bbox
produces Bbox('array([[ 0., 0.],\n [ 0., 0.]])')
. The method .get_window_extent(renderer)
works fine with text, lines, and patches, so I was a bit surprised to see it does not work with images.
In case it matters, I am using Matplotlib 1.3.0 with the TkAgg backend.