拉斯维加斯(Scala / Spark / Vega)为每个数据点上色

时间:2018-08-14 17:04:46

标签: scala apache-spark vega vega-lite vegas-viz

Vegas("A scatterplot").
  withDataFrame(neuronnet_activation_df).
  mark(Point).
  encodeX("s", Quantitative).
  encodeY("d", Quantitative).
  encodeColor(field="feature_0_prediction",scale=Scale(rangeNominals=List("#c41f01", "#00c610"))).
  show

是否可以用特定的RGB或aRGB值绘制每个点? 我已经计算出了颜色,因此不需要使用范围,而且我的数据的颜色范围也不是线性的。

1 个答案:

答案 0 :(得分:1)

我不确定这是如何映射到Vegas语法的,但是在Vega-Lite中,您可以通过将颜色代码作为数据传递并将颜色比例设置为null来实现。例如:

{
  "data": {
    "values": [
      {"s": 1, "d": 1, "color": "#c41f01"},
      {"s": 3, "d": 3, "color": "#00c610"}
    ]
  },
  "mark": {"type": "circle", "size": 200},
  "encoding": {
    "color": {"type": "nominal", "field": "color", "scale": null},
    "x": {"type": "quantitative", "field": "s"},
    "y": {"type": "quantitative", "field": "d"}
  },
  "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json"
}

Vega-Lite output