I would like to ask you if there is a way how to create a second x-axis in Altair (put the daytime on top)?
bar_cumm_TAGP = alt.Chart(df_TAGP_2[df_TAGP_2['simulation_date'] == '2020-10-
15']).mark_bar().encode(
alt.X('DVS:O'),
alt.X2('day:O'),
alt.Y(f'TAGP:Q', axis=alt.Axis(titlePadding=10, titleFontSize=14), title=""),
alt.Color(f'TAGP:Q', scale=alt.Scale(scheme='greens'))).properties(width=850, height=350)
line = alt.Chart(df_TAGP_2).mark_line(interpolate='basis', strokeWidth=2, color='#FB0000').encode(
alt.X('DVS'),
alt.Y('mean(TAGP)'))
alt.layer(bar_cumm_TAGP, line).resolve_scale(
x = 'independent'
)
My code snippet:
condition = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]
df_TAGP_2 = pd.DataFrame({
'day': pd.date_range('1990-01-01', freq='D', periods=10000),
'DVS': np.random.choice(condition , 10000,),
'TAGP': np.random.randint(4000, size=(10000)),
'simulation_date': '2020-10-15'})
My result:
Many thanks!



