im = ax.imshow(np.random.random((27, 27)), interpolation='nearest')
fig.canvas.mpl_connect('draw_event', print_pixel_coords)
fig.savefig('foo.png', dpi=fig.dpi)
How to map coordinates in AxesImage to coordinates in saved image file?