Reputation: 23
Let's say I would like to plot ['foo', 'bar', 'test']
with the respective colors ['blue', 'yellow', 'green']
. My suggestion to solve this is as following:
alt.Chart(df, height=600, width=1100).mark_circle(size=100).encode(
x='x',
y='y',
color=alt.Color('title:N', legend=None, scale=alt.Scale(range=['blue', 'yellow', 'green'])),
tooltip=['sample', 'title']
).properties(
selection=click
).interactive()
But this seems to pick the colors in an arbitrary order, and not in an ascending order as I expected. I would like foo
to be assigned the blue
color and bar
should become yellow
and so on.
Is it possible to link this (labels and colors) somehow?
Upvotes: 2
Views: 388
Reputation: 86330
There is some information on this in the docs in the Customizing Colors section. Briefly, if you would like to control which values are assigned to which colors, you can use the domain
argument:
scale = alt.Scale(domain=['foo', 'bar', 'test'], range=['blue', 'yellow', 'green'])
Upvotes: 2