Geo-Mapping with Folium
If you are ever working with geographic data, you’ll find an awesome tool for visualization in the Folium library. Here we’ll demonstrate how to graph geographic locations in python from Jupyter Notebook.
First, open your Jupyter Notebook and install folium.
!pip install folium
import folium
You’ll need the latitude and longitude of the location you’d like to map. For the sake of argument, let's map Brooklyn NY (AKA The Planet). We’ll define the variables for latitude and longitudes:
brooklyn_lat = 40.650002
brooklyn_long = -73.949997
Next, we’ll define the object to be mapped:
brooklyn_map = folium.Map([brooklyn_lat, brooklyn_long])
brooklyn_map
We can also add a marker to the map:
brooklyn_marker = folium.Marker([brooklyn_lat, brooklyn_long])
brooklyn_marker.add_to(brooklyn_map)
brooklyn_map
Great! Now I know where I am! But after 8 months of COVID, I’m getting a bit tired of Brooklyn so just for kicks let's go somewhere else. Tibet is about as far away from Brooklyn as possible so let's go there:
lhasa_lat = 29.654839
lhasa_long = 91.140549
Lhasa_Map = folium.Map([lhasa_lat, lhasa_long])
Lhasa_Map
Well, now I really don’t know where I am. I’d better add a marker:
Lhasa_marker = folium.Marker([lhasa_lat, lhasa_long])
Lhasa_marker.add_to(Lhasa_Map)
Lhasa_Map
Now If I only had a tour guide!