hvplot-如何通过分类变量为点数据着色并使用ds.count_cat(。)进行聚合

时间:2019-06-07 22:21:52

标签: python holoviews datashader pyviz hvplot

我正在尝试使用datashader census重新创建hvplot类别示例。

import cartopy.crs as ccrs
import datashader as ds
import dask.dataframe as dd
import hvplot.dask


ddf = dd.read_parquet("census2010.parq").persist()

ddf.hvplot.points(x="easting", y="northing", 
                  aggregator=ds.count_cat("race"),
                  datashade=True,
                  crs=ccrs.GOOGLE_MERCATOR)

不幸的是,我得到了:

WARNING:param.dynamic_operation: Callable raised "ValueError('Aggregation column race not found on :Points   [easting,northing] element. Ensure the aggregator references an existing dimension.',)".

1 个答案:

答案 0 :(得分:1)

事实证明,我没有在任何holoviews尺寸中定义要在“ race”上着色的变量。可以通过vdims将其添加到c="race"中(c表示要在其上进行着色的列):

enter image description here

完整代码应为(包括自定义颜色图):

 ddf.hvplot.points(x="easting", y="northing", 

                      c="race",
                      cmap={'w':'aqua', 'b':'lime',  'a':'red', 'h':'fuchsia', 'o':'yellow' }

                      aggregator=ds.count_cat("race"),
                      datashade=True,
                      crs=ccrs.GOOGLE_MERCATOR,
                     ).opts(bgcolor="black")

enter image description here