Basemap Heat error / blank card

I am trying to build a scattered heat map at a specific geographic location. I can very well build a normal scattered map without a background, but I want to combine it with the given lat and lon parameters. I get the next blank card enter image description here .

Enter

Input: col[2] and col[3] are the x and y coordinates and the geographical location Lat: 19.997453 , Lon: 73.789802

 000000000023 61.0 19.006113 73.009168 000000000054 65.0 19.009249 73.000342 000000000003 19.0 19.001051 73.000080 000000000012 20.0 19.009390 73.008638 000000000061 82.0 19.008550 73.003605 000000000048 86.0 19.006597 73.001057 00000000005d 60.0 19.003857 73.009618 000000000006 60.0 19.003370 73.009112 000000000037 91.0 19.002558 73.000546 000000000047 32.0 19.006061 73.008239 

Program

 from matplotlib import pyplot as plt from matplotlib import cm as CM from matplotlib import mlab as ml from mpl_toolkits.basemap import Basemap import numpy as np m = Basemap(width=12000000, height=9000000, projection='lcc', resolution='c', lat_0=19.,lon_0=73.) m.drawcoastlines(linewidth=0.25) data = np.loadtxt('random_lat_lon_0', unpack=True, dtype='str, float, float, float') x = data[2] y = data[3] z = data[1] gridsize = 100 m.hexbin(x, y, C=z, gridsize=gridsize) cb = m.colorbar() #m.set_label('Density') plt.show() 

There is no mistake. But I see only a blank card, but there is no data scatter.

How to fix? Thanks!

+6
source share
1 answer

Now I got it. You are trying to combine the answers received from here-imshow and here-hexbin .

Your problem comes down to the fact that you want to use your base map as a β€œcanvas” on which you build your 2D histogram. But instead, you make a Basemap and then draw a 2D histogram separately (using plt.hexbin , which makes a separate canvas from your base map).

Use m.hexbin and get rid of plt.imshow() . If you really want to use imshow, you first need to create an array of 2D histograms and then build it with imshow. The following is an example of using hexbin .


EDIT . Below, I randomized some x, y, z data so that I can make the plot (and make the shorelines bigger). It is not perfect, but displays data.

 from matplotlib import pyplot as plt from matplotlib import cm as CM from matplotlib import mlab as ml from mpl_toolkits.basemap import Basemap import numpy as np m = Basemap(width=12000000, height=9000000, projection='lcc', resolution='c', lat_0=19.,lon_0=73.) m.drawcoastlines(linewidth=0.25) # I added color='red', lw=2.0 #data = np.loadtxt('inputfile', unpack=True, dtype='str, int, int, int, int, float') # #x = data[1] #y = data[2] #z = data[5] x, y, z = np.random.rand(3, 1000000) x *= 12e6 y *= 9e6 z *= 20000 gridsize = 100 m.hexbin(x, y, C=z, gridsize=gridsize, cmap=plt.cm.YlGnBu) cb = m.colorbar() m.set_label('Density') plt.show() 

enter image description here

+2
source

Source: https://habr.com/ru/post/987222/


All Articles