Skip to content

How to apply color scale by field range? #2916

Discussion options

You must be logged in to vote

If you ever want to compare your Altair code to the Vega-Lite code, a good trick is to evaluate print(chart.to_json()), which can sometimes help with spotting the problem (maybe not as much in this particular example).

I believe this will work:

color=alt.Color('label:N',scale=alt.Scale(range={"field": "color"}))

@mattijn Do you see a nicer way than explicitly specifying this dictionary, {"field": "color"}?

In a soon-to-be-released version of Altair, you can skip the alt.Scale portion:

color=alt.Color('label:N').scale(range={"field": "color"})

There is also an option to use the raw color values directly, but I couldn't figure out a nice way to also get your labels to show up with this ap…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aborruso
Comment options

Answer selected by aborruso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants