How do kdims work for polygons in geoviews?

2019-07-31 11:09发布

I'm trying to understand how the kdims work for Polygon plots in geoviews. There is a similar question here but it hasn't really been answered - GeoViews: add a slider to chloropleth with Polygon geometries

In http://geo.holoviews.org/user_guide/Geometries.html the line

gv.Polygons(world, vdims='pop_est')

yields a world map with polygons shaded by population, and I think what it's somehow doing is getting lat/long as the kdims but I don't understand how this works. If I try to specify 'geometry' as the kdims I get an error "Expected two kdims to use GeoDataFrame, found 1."

My end goal is to be able specify the kdims so that I can also specify a "year" parameter as the kdims and get a scrollbar on the map.

1条回答
倾城 Initia
2楼-- · 2019-07-31 11:45

I think you are looking for something like (see also here: https://nbviewer.jupyter.org/github/poplarShift/pyviz-recipes/blob/master/notebooks/data_formats.ipynb)

import geoviews as gv
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
import holoviews as hv
hv.extension('bokeh')

hv.Dataset(world, kdims=['Longitude', 'Latitude', 'continent'], vdims='pop_est').to(gv.Polygons)
查看更多
登录 后发表回答