如何在holoviews / hvplot中将不同的列渲染为不同的颜色?

时间:2019-01-11 16:32:30

标签: pandas holoviews

我有一个熊猫数据框,其中包含两列时间序列数据。在我的实际数据中,这些列足够大,以至于没有数据着色器时渲染将变得笨拙。我正在尝试比较这两个时间序列中的事件。但是,我需要能够分辨出哪个数据点来自哪一列。下面是一个简单的功能示例。我如何让A列和B列使用不同的颜色图?

print(classification_report(y_true, y_pred))


              precision    recall  f1-score   support

           0       0.50      1.00      0.67         2
           1       0.00      0.00      0.00         2
           2       0.00      0.00      0.00         2

   micro avg       0.33      0.33      0.33         6
   macro avg       0.17      0.33      0.22         6
weighted avg       0.17      0.33      0.22         6

[...] UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. 
  'precision', 'predicted', average, warn_for)

1 个答案:

答案 0 :(得分:1)

您将必须使用count_cat聚合器来分别对每个类别进行计数,例如在上面的示例中,看起来像这样:

import datashader as ds
df.hvplot(kind='scatter', aggregator=ds.count_cat('Variable'), datashade=True,
          height=500, width=1000)

此处的'Variable'对应于hvplot分配给各列的默认group_label。如果您提供了不同的group_label,则必须更新聚合器以使其匹配。但是,除了显式提供聚合器之外,您还可以使用by关键字:

df.hvplot(kind='scatter', by='Variable', datashade=True,
          height=500, width=1000)

hvplot 0.3.1发布后,您还可以提供明确的cmap,例如:

df.hvplot(kind='scatter', by='Variable', datashade=True,
          height=500, width=1000, cmap={'A': 'red', 'B': 'blue'})

enter image description here