For any given chart, I'd like to specify the first n colors for alt.Scale(range=), and then if there are _n+1_ data values, for Altair to fallback on color scheme, e.g.
'category10'`.
In the following example, if there are 6 name
values, Altair will render them in red
and green
in a cyclical sequence:
chart = alt.Chart(df).mark_bar().encode(x='name', y='amount',
fill=alt.Color('name',
scale=alt.Scale(range=['red', 'green'])))
However, what I would like to happen is for name
values 3 through 6 to be, say, the first 4 colors of a scheme, like category10
. Pretend the Altair API recognized this kind of call (it doesn't, obviously, just trying to explain in code):
chart = alt.Chart(df).mark_bar().encode(x='name', y='amount',
fill=alt.Color('name',
scale=alt.Scale(range=['red', 'green'], scheme='category10'
)))
I guess another way I could ask my question is, is there a way to access a colorscheme object, and then manually tweak its color sequence? Here's another pseudocode explanation of what I mean:
mycolors = alt.Scale(range=['red', 'green']) + alt.Scale(scheme='category10')
chart = alt.Chart(df).mark_bar().encode(x='name', y='amount',
fill=alt.Color('name', scale=mycolors))
According to this answer from jakevdp, "the color palette details are not available via Altair from the Python package itself", which makes sense. But is there a way to essentially to designate/customize a new scheme, using existing specified schemes?