Heat map in Python

0

I was trying to make a heat map similar to this

However,whenIruntheprogram,Igetonlyablankmap

ForthisprojectIusedSpyder(pandasandgmplot)andthecodewasthis:

importpandasaspdimportjsonimportosfrompandas.io.jsonimportjson_normalizemap_name='map'map_center_lat=41.336924map_center_long=-8.557212cord_low_lat=41.335888cord_high_lat=41.337403cord_low_long=-8.569776cord_high_long=-8.570515google_json_path=r'C:\Users\Asus\Desktop\Takeout\LocationHistory\LocationHistory.json'zoom_level=13coordinate_resolution=3defplot_map(plot_df,map_name):importgmplotgmap=gmplot.GoogleMapPlotter(map_center_lat,map_center_long,zoom_level)gmap.scatter(plot_df.short_lat.tolist(),plot_df.short_long.tolist(),'#FF6666',edge_width=10)gmap.heatmap(plot_df.short_lat.tolist(),plot_df.short_long.tolist())gmap.draw(map_name+"_map.html")          

def open_html_map(html_path):
   import webbrowser           
   chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
   webbrowser.get(chrome_path).open(html_path)

with open(google_json_path, 'r') as f:
    data = json.load(f)

df = json_normalize(data,'locations')

df['latitudeE7'] = df['latitudeE7'].fillna(0.0).astype(float)
df['longitudeE7'] = df['longitudeE7'].fillna(0.0).astype(float)

df['latitude'] = df.apply(lambda x: x['latitudeE7']/10000000.0,axis = 1)
df['longitude'] = df.apply(lambda x: x['longitudeE7']/10000000.0, axis = 1)

del df['longitudeE7']
del df['latitudeE7']

df2 = pd.DataFrame()
df2['latitude'] = df['latitude']
df2['longitude'] = df['longitude']

df2['short_lat'] = df2.apply(lambda x: ((x['latitude']).round(decimals = coordinate_resolution)), axis = 1)
df2['short_long'] = df2.apply(lambda x: ((x['longitude']).round(decimals = coordinate_resolution)), axis = 1)

df2 = df2.groupby(['short_lat','short_long']).agg({'latitude':'count'}).reset_index()
del df2['latitude']

df2.query('short_lat > ' + str(cord_low_lat), inplace = True)
df2.query('short_lat < ' + str(cord_high_lat), inplace = True)
df2.query('short_long > ' + str(cord_low_long), inplace = True)
df2.query('short_long < ' + str(cord_high_long), inplace = True)

plot_map(df2, map_name)
open_html_map(os.getcwd() + '/' + map_name +"_map.html")
    
asked by anonymous 28.02.2018 / 20:34

0 answers