0

I am trying to plot a GeoTIFF that was initially created in QGIS. When saving the file, I export the GeoTIFF with the raw data to prevent errors while making the appropriate color map for matching the meta-data. For more context, I am saving a sub-set of the CS3 land use NetCDF. After I have saved the GeoTIFF to a specific extent, I open it with Georaster, get the image boundaries, and plot it with imshow. To make sure I have the correct color pallet for the color map, I read the GeoTIFF, save all pixel values in an array, and look for all possible values to account for in the color map list. The value array looks as follows:

Raster value list [10, 11, 12, 20, 30, 40, 50, 60, 61, 62, 70, 90, 100, 110, 120, 
122, 130, 150, 153, 160, 170, 180, 190, 200, 210, 220]

And this is the array of the corresponding colors:

flag_colors = [ '#ffff64', '#ffff64', '#ffff00', '#aaf0f0','#dcf064', '#c8c864', 
'#006400', '#00a000','#00a000', '#aac800', '#003c00', '#788200','#8ca000', 
'#be9600','#966400','#966400','#ffb432', '#ffebaf','#ffebaf','#00785a', '#009678', 
'#00dc82', '#c31400','#fff5d7','#0046c8', '#ffffff']

So when I plot the file with the following script:

my_image = georaster.SingleBandRaster(geotif_path, load_data=False) 
minx, maxx, miny, maxy = my_image.extent

nc = georaster.SingleBandRaster(geotif_path, load_data=(minx, maxx, miny, maxy), 
latlon=True)

cmap = ListedColormap(flag_colors)

ax.imshow(nc.r, cmap=cmap, vmin=10, vmax=220, extent=(minx, maxx, miny, maxy))

I get this image:

enter image description here

But what I was expecting something like this: enter image description here

Even though I included all the colors in the array for the values in the GeoTIFF file, I not getting the correct colors on the plot.

Thank you in advance!

1 Answer 1

0

I have found a solution to my issue. For those with a similar issue, the following code will normalize the color scheme based on the number of colors I wanted to customize my color map. I also remembered that I needed to interpolate my data. In this case, I have used the "nearest" to scale my raster data.

To customize the color map:

cmap, norm = colors.from_levels_and_colors(flag_values, flag_colors, extend='max')

To plot raster data with a customized color map:

ax.imshow(nc.r, cmap=cmap, norm=norm, extent=(minx, maxx, miny, maxy), 
zorder=1, interpolation='nearest')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.