Search code examples
pythonplotgeospatialkepler.gl

How to make Kepler.gl plots consistent


I'm using kepler.gl to create some geographical plots.
I want to create some setting for the plot and than set these as default for when I run the cell containing that plot.

These are the steps:

  1. I copied the conf from Kepler.gl website from Share>Share Map> Map Config.
  2. I pasted the copied text to my python notebook cell in the variable conf
conf = {. . .} # copied from the website after setting the correct visualization 
  1. I replaced all true with True, false with False etc.
  2. In the notebook I created a map and set the config
from keplergl import KeplerGl
import json

map1 = KeplerGl()
map1.add_data(data=gpd.read_file('my.geojson'), name='name1')
map1.config = conf
  1. I modified the label property in conf so that it would be equal to the name property inside the add_data function

Finally when I show the plot using
map1
It shows a basic plot of my geojson without any of the configurations in conf.

NB.
The geojson file I uploaded in Kepler.gl is the same file I used in KeplerGL() python function

I read online that it can be due to the IDs of the datasets but I don't understand how to make those IDs the same since I'm using the same dataset.

Here's the documentation, personally I didn't manage to find the answer to my question in there but maybe there is and I didn't understand it.


Solution

  • You need to pass the value of the name that you define in the map1.add_data()to the dataId property (instead of the label) of your config.

    So in your exapmpe:

    "dataId": ["name1"]
    

    💡Important: Depending on your style settings the field "dataId" might exist more than once. You need to replace the value of all instances.