1

I have a PyQt4 Application in which I am representing a 16bit grayscale image using matplotlib. The image I'm representing are quite large. Due to memory limitations I'm unfortunately not able to represent the bigger images, so I'm slicing them in this way:

ImageDataArray[::ratio, ::ratio]

When showing the plots, the axis are compressed depending on the ratio. Hence the coordinates of the image is of importance to know where the information of interest is loacated, I want to stretch the axis again by the factor of ratio.

How can I manage this, so the correct coordinates are shown even if I use the zoom function from the matplotlib toolbar?

Thanks in advance.

Code:

from numpy import fromfile, uint16, shape
import matplotlib.pyplot as plt

data = fromfile('D:\\ImageData.raw', dtype=uint16)
data.resize((ysize,xsize))
xmin = 0
ymin = 0
xmax = shape(data)[1]
ymax = shape(data)[0]
ratio = max(max(shape(data)[0], shape(data)[1])/2000, 1)
data_slice = data[ymin:ymax:ratio, xmin:xmax:ratio]
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.imshow(data_slice, cmap='gray', interpolation='nearest')
plt.show()
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
FunCoder
  • 33
  • 3

1 Answers1

2

You want to use the extent keyword argument of imshow (doc)

ax.imshow(...,extent=[xmin,xmax,ymin,ymax])
tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • Just to add, [this post](https://stackoverflow.com/questions/13384653/imshow-extent-and-aspect) explains how to maintain your aspect ratio. – orodbhen Apr 13 '18 at 16:44