#!/usr/bin/env python # coding: utf-8 # # Introduction to Unfolded Map SDK # # [![open_in_colab][colab_badge]][colab_notebook_link] # [![open_in_binder][binder_badge]][binder_notebook_link] # # [colab_badge]: https://colab.research.google.com/assets/colab-badge.svg # [colab_notebook_link]: https://colab.research.google.com/github/foursquare/unfolded-sdk-examples/blob/master/notebooks/01%20-%20Introduction.ipynb # [binder_badge]: https://mybinder.org/badge_logo.svg # [binder_notebook_link]: https://mybinder.org/v2/gh/foursquare/unfolded-sdk-examples/master?urlpath=lab/tree/notebooks/01%20-%20Introduction.ipynb # This notebook demonstrates how to create a local Unfolded map and then how to add a simple dataset to it. # ## Dependencies # # This notebook requires the following Python dependencies: # # - `unfolded.map-sdk`: The Unfolded Map SDK # - `sidecar`: Jupyter sidecar widget to allow rendering Unfolded Studio in a sidebar. # - `pandas`: DataFrame library # # If running this notebook in Binder, these dependencies should already be installed. If running in Colab, the next cell will install these dependencies. # In[ ]: # If in Colab, install this notebook's required dependencies import sys if "google.colab" in sys.modules: get_ipython().system("pip install 'unfolded.map_sdk>=1.0' sidecar pandas") # ## Imports # In[ ]: from unfolded.map_sdk import create_map from sidecar import Sidecar import pandas as pd # ## Creating a Map # First, let's create a map instance: # In[ ]: 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: # In[ ]: unfolded_map # In Jupyter Lab we also have the option of displaying a map as a separate side pane using the [`Sidecar`](https://github.com/jupyter-widgets/jupyterlab-sidecar) package. In other environments than Jupyter Lab, using `sidecar` will probably not work. # In[ ]: sc = Sidecar(title='Unfolded Map', anchor='split-right') with sc: display(unfolded_map) # ## Adding data # We can now add a dataframe as a dataset to the map: # In[ ]: 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] }) }) # ## Set view state # Now let's change the map viewport to better see the data points we just added: # In[ ]: 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.