0

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:

src=rasterio.open('14072020.tif')

#Display the image 
plt.figure(figsize=(20,10))
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
plt.figure(figsize=(20,10))
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?

1

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

src=rasterio.open('14072020.tif')
 
plt.figure(figsize=(20,10))
show(src.read(4), transform=src.transform, title='Gray Scale - Band 4', cmap='gray') 
| improve this answer | |

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.