Reputation: 2553
While drawing a chart with many layers, some layers have mismatched colors.
I tried fixing this using an alt.Scale. The problem is that the colors do not match the theme I had selected. I would like to be able to use the current themes colors, but be able to choose which one is used for each element in the chart.
In particular, this is my code:
make_era_labels = lambda df_slice, mode : \
alt.Chart(df_slice).mark_text(
align='right' if mode == 'high' else 'left',
baseline='top',
size = 14,
fontWeight='bold',
angle = 270,
dx = -20,#120,
dy=20,#25
).encode(
text='Era',
x=alt.X('start', title = x_axis),
y=alt.value(0 if mode =="high" else 600), # pixels from top
color=alt.Color('Era',
legend = None,
scale=alt.Scale(
domain=['Pre Deep Learning Era', 'Deep Learning Era', 'Large Scale Era'],
range=['yellow', 'blue', 'red']) if large_scale_action == 'isolate' else alt.Undefined
)
)
midpoint = pd.to_datetime(f"{(year_start.year + year_end.year) // 2}-01-01")
left_era_labels = make_era_labels(eras_df[eras_df['start'] < midpoint], "high")
right_era_labels = make_era_labels(eras_df[eras_df['start'] > midpoint], "low")
Since I am making the graph in two parts, the colors are not coordinated, and the first color of the scheme is repeated. But when I chose the colors myself with an alt.Scale
the colors do no longer match the theme.
Instead of range=['yellow', 'blue', 'red']
I would like to have colors corresponding to the current theme. For example, the yellow
as it appears now is too bright.
I tried to use alt.themes.get()
but that just unhelpfully returns VegaTheme('fivethirtyeight')
, the name of the theme I am using.
Upvotes: 0
Views: 1741
Reputation: 48919
You can see all colors by going to https://vega.github.io/vega/docs/schemes/ and hovering the names in the color schemes (also defined here https://github.com/vega/vega/blob/v5.21.0/packages/vega-scale/src/palettes.js)
There are some related answers in this question Altair: Selecting a color from a Vega color scheme for plot
Upvotes: 1