I have sentinel 2 image and I use rasterio to display it. I am using "imshow" to display it. when I display it, it doesn't show any coordinates:


#Display the image 
plt.imshow(src.read(4), cmap='gray')
plt.title('Gray Scale - Band 4')

enter image description here

I have ried to add it like this:

plt.imshow(src.read(4),transform=src.transform, cmap='gray')

but then I get error message:

TypeError: 'transform' must be an instance of matplotlib.transforms.Transform, not a affine.Affine

the weird thing is that if I display 3 bands together it appears:

#RGB image
show(src.read([4,3,2]),transform=src.transform,title='Image- bands 4,3,2 IN 0-255 Values',vmin=0,vmax=30000)

enter image description here

Why is this happen? is there any way I can control add coordinates to the one band image?


Your used matplotlib.pyplot.imshow() to show the first grayscale image, and rasterio.plot.show() for the second RGB one.

Use show() to display the first grayscale image (Band 4), too;

from rasterio.plot import show
import matplotlib.pyplot as plt

show(src.read(4), transform=src.transform, title='Gray Scale - Band 4', cmap='gray') 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.