How to display an image over a map with imshow?

I have a geotype with 9 different color values ​​(0-9) and want to display it on a map. I am trying to use it with a basemap from the matplotlib package.

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

im = plt.imread('a.tif')
extent = [-18, 52, -38, 38] # [left, right, bottom, top]
m = Basemap(projection='merc', llcrnrlon=extent[0], urcrnrlon=extent[1], llcrnrlat=extent[2], urcrnrlat=extent[3], resolution='c')
m.drawcountries() 
plt.imshow(im, extent=extent, alpha=0.6)
plt.show()

      

I only get black and white image. When I uncomment drawcountries (), I see data from the tif.

How can I draw tif colors on the map and add country borders?

+3


source to share


2 answers


m.imshow(im, extent=extent, alpha=0.6)

      



+4


source


Using a degree doesn't solve your problem! This poses a big problem because it looks ok but it is wrong.

The degree will only work for cylindrical protrusions and keeping distances. It just adjusts the image to some kind of rectangle, linearly! The mercator projection is not linear.



Try using the "cyl" projection. So the answer is: there is no possibility for non-linear transformations. A possible workaround is to convert the image coordinates to distances in a new projection and then 2d interpolation (matplotlib.tri for example) to some new rectangle (of the distances).

+2


source







All Articles