I have a list of GeoTIFF files, which I uploaded to a repo in Github. The files are generated in R, there I can read them with the raster
library :
> library(raster)
Loading required package: sp
> r = (raster::raster("./2020-07-24_B.tif"))
class : RasterLayer
dimensions : 36, 28, 1008 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : 680460, 680740, 4183700, 4184060 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=30 +datum=WGS84 +units=m +no_defs
source : 2020-07-24_B.tif
names : X2020.07.24_B
values : 687, 1494 (min, max)
raster::plot(r)
The files load nicely in QGIS:
But I am unable to make them work in Python:
import rasterio as rs
from matplotlib import pyplot
file = "B/2020-07-24_B.tif"
raster = rs.open(file)
array = raster.read()
pyplot.imshow(array[0])
I followed this tutorial.
At this point I wonder if the file could be corrupted in some way or is just an issue related with the tweaking of imshow
params.
Best Answer
Yes. It is just an issue related with the parameters. Without
vmin
andvmax
, matplotlib uses nodata value as minimum value, and stretches the color map.So, you need to specify min and max value:
Instead of
pyplot.imshow
, you can use rasterioshow
method.