Polygons#
import hvplot.pandas # noqa
Using hvplot with geopandas is as simple as loading a geopandas dataframe and calling hvplot
on it with geo=True
.
import geopandas as gpd
countries = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
countries.sample(5)
/tmp/ipykernel_2328/3247875238.py:3: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.
countries = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
pop_est | continent | name | iso_a3 | gdp_md_est | geometry | |
---|---|---|---|---|---|---|
120 | 1326590.0 | Europe | Estonia | EST | 31471 | POLYGON ((27.98113 59.47537, 27.98112 59.47537... |
34 | 5047561.0 | North America | Costa Rica | CRI | 61801 | POLYGON ((-82.54620 9.56613, -82.93289 9.47681... |
163 | 100388073.0 | Africa | Egypt | EGY | 303092 | POLYGON ((36.86623 22.00000, 32.90000 22.00000... |
89 | 299882.0 | Oceania | Vanuatu | VUT | 934 | MULTIPOLYGON (((167.21680 -15.89185, 167.84488... |
5 | 18513930.0 | Asia | Kazakhstan | KAZ | 181665 | POLYGON ((87.35997 49.21498, 86.59878 48.54918... |
countries.hvplot(geo=True)
Control the color of the elements using the c
option.
countries.hvplot.polygons(geo=True, c='pop_est', hover_cols='all')
You can even color by another series, such as population density:
countries.hvplot.polygons(geo=True, c=countries.pop_est/countries.area, clabel='pop density')
/tmp/ipykernel_2328/2205615459.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
countries.hvplot.polygons(geo=True, c=countries.pop_est/countries.area, clabel='pop density')