Plotting Maps#

../_images/earth.jpeg

By NASA - Public Domain via Wikimedia, also see original source

To Earth#

Your sensors have picked up a colony of pandas on a remote class M planet. You suspect they are being held captive by a primitive species of two-legged aliens. It is also possible that the pandas are mind-controlling their captivators to treat them well. Your mission is to send a scouting party on the planets surface to find out.

Your rescue team will need an accurate map of the area.

You have the coordinates are 30.73861, 104.14276. But you are not too familiar with the local longitude/latitude system. Or was it latitude/longitude?

Just plot that map!

The folium Library#

folium is a Python map plotting library built on top of the JavaScript library leaflet (hence the name). folium uses map tiles from OpenStretMap It produces HTML documents:

Use pip to install the folium package:

pip install folium

Draw a map#

First, define coordinates in a variable:

coord = (..., ...)

Then draw the map with a marker on the panda colony:

import folium

colony_map = folium.Map(location=coord, zoom_start=13)
folium.Marker(
    coord,
    popup="Panda Colony",
    icon=folium.Icon(icon="map-marker", color="blue"),
).add_to(colony_map)

In Jupyter, you can display the map interactively:

colony_map

Save the map#

You can save the map to a HTML file:

colony_map.save("colony_map.html")