Does varying extent in imshow() lead to changes in pixel number while rendering the image?

364 Views Asked by At

I went through the tutorial origin and extent in imshow and also through the documentation of extent in imshow(). It was mentioned there that pixels have unit size in data coordinates,their centers are on integer coordinates. Hence varying the extent parameter should control the number of pixels in the rendered image. I want to verify this. My idea is to make a 10x10x3 RGB data-array and plot it using imshow() with default extent. Then plot the same data-array with imshow(), but modifying extent to ensure a higher number of pixels. I am stuck when I am required to verify if the two rendered images indeed have a difference of pixel count.

Below is the code to express the idea -

import numpy as np
import matplotlib.pyplot as plt

# Make a 10x10x3 RGB data-array
x = np.linspace(1,10,10)
X,Y = np.meshgrid(x,x)
r = np.sqrt(X**2 + Y**2)
R = X/r
G = (np.sqrt(2*X*Y))/r
B = Y/r
data = np.stack([R,G,B],axis=-1)

fig, (ax1,ax2) = plt.subplots(1,2)

# image with supposedly lower pixels
im1 = ax1.imshow(data,origin='lower')
ax1.set_title('Lower expected pixel')

# image supposedly higher pixels
im2 = ax2.imshow(data,origin='lower',extent=(-0.5,99.5,-0.5,99.5))
ax2.set_title('Higher expected pixel')

Output

My primary questions here are -

  • Is my guess "changing extent changes pixel count" correct?
  • How to perform the verification that I referred to above?
0

There are 0 best solutions below