【问题标题】:Vegas (Scala/Spark/Vega) color every data pointVegas (Scala/Spark/Vega) 为每个数据点着色
【发布时间】:2019-01-21 14:40:29
【问题描述】:
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 值绘制每个点? 我已经计算了颜色,所以我不需要使用范围,而且我的数据的颜色范围也不是线性的。

【问题讨论】:

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


    【解决方案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"
    }
    

    【讨论】:

    • 谢谢。我找到了使用您的信息的解决方法。 encodeColor(field="color",Nominal,scale=Scale()).toJson.replaceFirst("\\{\\s*\\}","null") 它并不完美,但它可以完成工作。也许有人知道更好的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2020-08-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多