Troubleshooting colors in pydeck

58 Views Asked by At

I'm having trouble getting colors to work in pydeck (exacerbated by the fact there aren't error messages to hint at the problem). In particular I'm using an H3ClusterLayer.

Using an explicit color e.g. get_fill_color=[0,255,255] works. The problem is that I'd like to use different colors for different clusters, and I can't get that to work.

Here's a MWE. Working version:

import pandas as pd
import pydeck as pdk
from h3 import h3

polygons = [
        {'type' : 'Polygon', 'coordinates' : [[[44,-115],[46,-98],[41,-88],[41,-110]]]},
        {'type' : 'Polygon', 'coordinates' : [[[38,-110],[39,-88],[34,-92],[36,-118]]]},
        ]
hexes = [list(h3.polyfill(polygon, 3)) for polygon in polygons]
color = [
        [0,255,255],
        [200, 100, 0],
        ]
tooltip = ['foo', 'bar']

df = pd.DataFrame({'tooltip' : tooltip, 'hexes' : hexes, 'color' : color})

layer = pdk.Layer(
        'H3ClusterLayer',
        df,
        pickable=True,
        stroked=False,
        filled=True,
        extruded=False,
        opacity=0.25,
        get_hexagons='hexes',
        get_fill_color=[0,255,255],
)

view_state = pdk.ViewState(latitude=38.2, longitude=-96.9, zoom=4, bearing=0, pitch=0)
r = pdk.Deck(
        layers=[layer],
        map_style='light',
        initial_view_state=view_state,
        tooltip={'text' : '{tooltip}'}
)
r.to_html("test.html")

For me the output looks like this: working version

Broken version: exactly the same, but changing get_fill_color=[0,255,255] to get_fill_color='color'. I expect this to work based on the documentation, but instead the result looks like this: broken version

I can tell that something is happening because the tooltip still appears over where the hexes should be, but the hexes themselves don't appear.

Any idea on how to troubleshoot this?

0

There are 0 best solutions below