I have two dataframes with seperate data that cannot be joined. I would like to create two charts, and use an interval_selection on one to filter data-points in the other. Below is my attempt to do so:
import altair as alt
import pandas as pd
brush = alt.selection_interval(encodings=['x'])
df = pd.DataFrame({
'date': pd.to_datetime(['2022-01-03', '2022-01-04', '2022-01-04', '2022-01-05', '2022-01-06']),
'x_value': [1., 2., 4., 3., 5.],
'y_value': [4., 3., 2., 5., 1.],
})
other_data = pd.DataFrame({'date_col': pd.to_datetime([f'2022-01-0{i}' for i in range(1, 10)])})
scatter = alt.Chart(df).mark_point().encode(
x='x_value:Q',
y='y_value:Q',
).transform_filter(
(alt.datum.date >= brush.x[0]) & (alt.datum.date <= brush.x[1]) # does not work
)
scatter2 = alt.Chart(other_data).mark_point().encode(x='date_col:T').add_selection(brush)
scatter & scatter2
Ideally, the code above should allow me to filter data pointers in scatter based on the date-range selected in scatter2. However, this plot does not render at all (the problematic line is indicated via a comment). How do I fix this? Thanks in advance!
