#!/usr/bin/env python # coding: utf-8 # # Geospatial histogram visualization using folium # # **Note: You need to have the `folium` package installed to run this notebook.** # # ### "Bagging" the munros into rectangular bins # # *A Munro (About this sound listen (help·info)) is a mountain in Scotland with a height over 3,000 feet (914 m). Munros are named after Sir Hugh Munro, 4th Baronet (1856–1919), who produced the first list of such hills, known as Munro's Tables, in 1891...* says Wikipedia, more in https://en.wikipedia.org/wiki/Munro. # # Let's show the possibility to plot histograms in the maps with the help of folium library. # In[1]: # Necessary import evil import physt.plotting physt.plotting.set_default_backend("folium") # In[2]: # Read the data from physt.examples import load_dataset munros = load_dataset("munros") munros.head() # In[3]: # How many of them are there? Wikipedia says 282 (as of 2017) munros.shape # ## How many munros are in each 10' rectangle? # In[4]: hist = physt.h2(munros["lat"], munros["long"], "fixed_width", bin_width=1 / 6) # In[5]: map = hist.plot() map # In[6]: # Now, let's combine this information with positions of the 20 tallest import folium map = hist.plot() for i, row in munros.iloc[:20].iterrows(): marker = folium.Marker([row["lat"], row["long"]], popup="{0} ({1} m)".format(row["name"], row["height"])) marker.add_to(map) map