This notebook demonstrates how to create a local Unfolded map and then how to add a simple dataset to it.
This notebook requires the following Python dependencies:
unfolded.map-sdk
: The Unfolded Map SDKsidecar
: Jupyter sidecar widget to allow rendering Unfolded Studio in a sidebar.pandas
: DataFrame libraryIf running this notebook in Binder, these dependencies should already be installed. If running in Colab, the next cell will install these dependencies.
# If in Colab, install this notebook's required dependencies
import sys
if "google.colab" in sys.modules:
!pip install 'unfolded.map_sdk>=1.0' sidecar pandas
from unfolded.map_sdk import create_map
from sidecar import Sidecar
import pandas as pd
First, let's create a map instance:
unfolded_map = create_map()
In environments that support Jupyter Widgets, such as Jupyter Notebook, JupyterLab, and Google Colab, simply put the map variable as the last or only line in a cell:
unfolded_map
In Jupyter Lab we also have the option of displaying a map as a separate side pane using the Sidecar
package. In other environments than Jupyter Lab, using sidecar
will probably not work.
sc = Sidecar(title='Unfolded Map', anchor='split-right')
with sc:
display(unfolded_map)
We can now add a dataframe as a dataset to the map:
unfolded_map.add_dataset({
'data': pd.DataFrame({
'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],
'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]
})
})
Now let's change the map viewport to better see the data points we just added:
unfolded_map.set_view({
'longitude': -60,
'latitude': -20,
'zoom': 2
})
There are many more things you can control in Unfolded maps via the SDK. Check out the rest of the examples in this directory.