-
Is it possible to get a color for a mark by specifying three different numerical columns as red, green and blue components of the mark's color? Something like:
...where Excessive googling suggests that it does not seem possible, but I'm hoping that I have overlooked something. Fun fact: I asked this to ChatGPT, and it very confidently suggests that there is an aggregate function in altair named |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is possible using so called expressions, see Expressions for interaction for an introduction. ChatGPT was onto something but it's not quite correct :) import altair as alt
import pandas as pd
df = pd.DataFrame(
[[1, 1, 102, 204, 0], [2, 2, 0, 0, 255], [3, 3, 0, 0, 0]],
columns=["x", "y", "r", "g", "b"],
)
alt.Chart(df).mark_circle(size=200).encode(
x="x",
y="y",
# In Altair 5 you will be able to replace alt.ExprRef with alt.expr
color=alt.value(alt.ExprRef(alt.expr.rgb(alt.datum.r, alt.datum.g, alt.datum.b))),
# Or you can write the expression as a string like this
# color=alt.value(alt.ExprRef("rgb(datum.r, datum.g, datum.b)")),
) |
Beta Was this translation helpful? Give feedback.
It is possible using so called expressions, see Expressions for interaction for an introduction. ChatGPT was onto something but it's not quite correct :)