Search code examples
dataframebokehholoviews

Holoviews Polygons inputs


I have been able to make a choropleth map in Bokeh using multiple lists (latitudes, longitudes, county names, value to display, color to display). I wanted to use Holoviews with Bokeh to get their color legend as I prefer it over Bokeh's disjoint grouping one.

In general, I have been unable to find good documentation on structuring a dataframe so that Holoviews can pull data from it. I found mentions of it on their GeoViews documentation, and tried to replicate the Choropleths example they give but cannot get it to work. How do dataframes need to be formatted for Holoviews?


Solution

  • If you are wanting to render polygons from dataframes in HoloViews/GeoViews you have one of two options:

    1) Use geopandas dataframes, which will work out of the box. Just pass your geopandas dataframe to the Polygons element and it will display itself.

    2) Pass in a list of dataframes one for each polygon, e.g. in the following example we create list of dataframes by creating Box elements and calling dframe on them. This list of dataframes can now be passed to the Polygons element:

    list_of_dfs = [hv.Box(0, 0, i/10.).dframe() for i in range(10, 1, -1)]
    hv.Polygons(list_of_dfs)