Using Kepler.gl in Jupyter Notebook for Geospatial Data Visualization
This tutorial introduces Kepler.gl, an open‑source geospatial visualization library from Uber, showing how to install it in a Jupyter notebook, create maps, load CSV or DataFrame data, customize charts via the GUI, retrieve configurations, and export the interactive map to HTML.
Kepler.gl Overview
Kepler.gl is an open‑source geospatial data visualization tool from Uber that can be used inside Jupyter notebooks to create interactive maps.
Installation
Install via pip:
<code>pip install keplergl</code>If you are on macOS with notebook version 5.3 or newer you can skip the nbextension steps; otherwise run:
<code>jupyter nbextension install --py --sys-prefix keplergl # can be skipped for notebook 5.3 and above
jupyter nbextension enable --py --sys-prefix keplergl # can be skipped for notebook 5.3 and above</code>Simple Example
Creating an empty map verifies the installation:
<code>from keplergl import KeplerGl
# create a KeplerGl object
map_1 = KeplerGl(height=500)
# display the map in the notebook
map_1</code>Adding Data
Kepler.gl accepts CSV, GEOJSON, and pandas DataFrame objects. The example below loads a CSV file with pandas and adds it to a map:
<code>import pandas as pd
df = pd.read_csv('rocket_launch_site_elevation_2019-10-27.csv')
df.head()</code> <code># create a KeplerGl object
map_2 = KeplerGl(height=600)
# display the map
map_2
# add the DataFrame as a layer named 'rocket'
map_2.add_data(name='rocket', data=df)
# display the updated map
map_2</code>Customizing the Chart
Unlike libraries such as pyecharts or matplotlib, Kepler.gl lets you configure colors, chart types, and other visual aspects through the graphical interface rather than extensive code.
Retrieving Configuration
You can obtain the current map configuration (including UI changes) with the .config attribute:
<code>map_2.config</code>Exporting the Map
Use .save_to_html() to export the map to an HTML file. Parameters include data , config , file_name (default keplergl_map.html ), and read_only to lock the map.
<code>map_3.save_to_html(file_name='kepler_example.html')</code>Opening the generated HTML file in a browser launches an interactive visualization.
Conclusion
Kepler.gl is easy to get started with, requiring minimal code for basic visualizations and offering a powerful GUI for creating attractive geospatial maps, making it a solid choice for projects that need geographic data visualization.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.