Hexbin Plots for Geospatial Data

tessellation, resolution and you

Hexplotlib

Geographic Pandemic

def draw_hexbin(df, grid=(20,20)):
x = df['Longitude']
y = df['Latitude']
C = df['Deaths']
plt.hexbin(x,y,C,gridsize=grid,)
plt.show()
plt.figure(figsize=(22,12))
draw_hexbin(df)
def draw_better_hexbin(df, grid=(120,120)):
x = df['Longitude']
y = df['Latitude']
C = df['Deaths']
hx = plt.hexbin(x,y,C,gridsize=grid, cmap='plasma', bins='log')
cb = plt.colorbar(hx)
plt.show()
plt.figure(figsize=(22,12))
draw_hexbin(df)

Basemapping Hexes

from mpl_toolkits.basemap import Basemap
x = df['Longitude']
y = df['Latitude']
C = df['Confirmed']
fig = plt.figure(figsize=(22,12))
m = Basemap() # create Basemap object
m.drawcoastlines() # draw coastlines
m.drawcountries() # draw political boundaries
# hexbin with prior parameters
m.hexbin(x,y,C=C, gridsize=(250), cmap='inferno', bins='log')
plt.show()
fig = plt.figure(figsize=(22,12))
m = Basemap()
m.drawcoastlines()
m.drawcountries()
m.shadedrelief() # graphic overlay
hx = m.hexbin(x,y,C=C, gridsize=(220), cmap='inferno', bins='log')
# the colorbar messed up the ratio scaling
plt.show()

data scientist, machine learning engineer. passionate about ecology, biotech and AI. https://www.linkedin.com/in/mark-s-cleverley/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store