I try to visualize the duration of air raid sirens in my country by date and time. There is one problem I'm struggling with. When the air siren starts one day and ends the next day it fills up the entire day of the plot.
E.g. air siren started on Mar 2, 23:21 (11:21 pm) and ended on Mar 3, 00:38 then the entire day would be filled out as you can see on the screenshot.
My code
alt.data_transformers.disable_max_rows()
dropdown = alt.binding_select(options=df.region.unique(), name='Select Region')
select_region = alt.selection_single(empty='none', bind=dropdown, fields=['region'], init={'region':'Київ'})
layer1 = alt.Chart(df).mark_rect().encode(
y=alt.Y('hours(siren_start_at):O', title='hour of day'
,axis=alt.Axis(format='%H:%M', grid=True)
,scale=alt.Scale(reverse=True)
),
y2=alt.Y2('hours(siren_end_at):O'),
x=alt.X('monthdate(siren_start_at):O', title='date', axis = alt.Axis(grid=True)),
tooltip = [
alt.Tooltip('monthdate(siren_start_date):O', title='siren started date')
,alt.Tooltip('hoursminutes(siren_start_at):O', title='siren started at')
,alt.Tooltip('monthdate(siren_end_date):O', title='siren end date')
,alt.Tooltip('hoursminutes(siren_end_at):O', title='siren ended at')
,alt.Tooltip('duration:Q', title='siren duration (min)')
]
).add_selection(select_region).transform_filter(select_region)
layer2 = alt.Chart(df).mark_rect().encode(
x=alt.X('monthdate(siren_start_at):O', title='date', axis = alt.Axis(orient='top', grid=True))
,y=alt.Y('hours(siren_start_at):O', title='hour of day'
,axis=alt.Axis(format='%H:%M', grid=True)
,scale=alt.Scale(reverse=True)
)
,y2=alt.Y2('hours(siren_end_at):O')
).transform_filter(select_region)
alt.layer(layer1, layer2).resolve_scale(
x = 'independent'
)
My data frame is stored here https://github.com/GendolfJunior/UA_air_sirens.
The full dataset is available here https://github.com/Vadimkin/ukrainian-air-raid-sirens-dataset. Credits to @Vadimkin.



