Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

3.6 KB
Raw Blame

Widget API

KeplerGl()

Create a kepler.gl map widget.

Parameters

  • height int optional default: 400

    Height of the map display in pixels.

  • data dict optional

    Datasets as a dictionary, key is the name of the dataset. Read more on Accepted data formats.

  • mapbox_token str optional default: ""

    Mapbox API access token. Required for Mapbox basemap styles (e.g. "Dark", "Muted Light"). Leave empty to use free MapLibre styles.

  • use_arrow bool optional default: False

    If True, serialize DataFrames as Arrow IPC for better performance on large datasets. Has no effect on GeoDataFrames, which always use GeoArrow serialization.

  • config dict optional

    Map config as a dictionary. The dataId in the layer and filter settings should match the name of the dataset they are created under.

  • show_docs bool optional

    Deprecated, kept for backward compatibility.

  • theme str optional default: ""

    UI theme for the map. Accepted values are "light", "dark", "base", or "" (default dark theme). See Map Customization for details.

  • app_name str optional default: "kepler.gl"

    Application name shown in the side panel header and used as the HTML <title> when exporting. See Map Customization for details.

Examples

# Load an empty map
from keplergl import KeplerGl
map_1 = KeplerGl()
map_1

empty map

You can also create the map and pass in the data or data and config at the same time. Follow the instruction to match config with data.

# Load a map with data and config and height
from keplergl import KeplerGl
map_2 = KeplerGl(height=400, data={"data_1": my_df}, config=config)
map_2

Load map with data and config


.add_data()

Add data to an existing map.

Parameters

  • data required CSV, GeoJSON, DataFrame or GeoDataFrame. Read more on Accepted data formats.
  • name optional default: "data". Name of the data entry.
  • use_arrow optional If True, serialize DataFrame as Arrow IPC. If None (default), falls back to the widget-level use_arrow setting.

name of the dataset will be saved to the dataId property of each layer, filter and interactionConfig in the config.

kepler.gl expects the data to be CSV, GeoJSON, DataFrame or GeoDataFrame. You can call add_data multiple times to add multiple datasets to kepler.gl.

# DataFrame
df = pd.read_csv('hex-data.csv')
map_1.add_data(data=df, name='data_1')

# CSV
with open('csv-data.csv', 'r') as f:
    csvData = f.read()
map_1.add_data(data=csvData, name='data_2')

# GeoJSON as string
with open('sf_zip_geo.json', 'r') as f:
    geojson = f.read()

map_1.add_data(data=geojson, name='geojson')

Add data to map


.data

Print the current data added to the map. Returns a dict.

map_1.data
# {'data_1': 'hex_id,value\n89283082c2fffff,64\n8928308288fffff,73\n89283082c07ffff,65\n89283082817ffff,74\n89283082c3bffff,66\n8...`,
#  'data_2': 'location, lat, lng, name\n..',
#  'data_3': '{"type": "FeatureCollection...'}