altair – link the y-axis to the x-axis of another chart

You can do this by creating the interaction manually, and then linking domains to the selection’s encodings; something like this:

x12_zoom = alt.selection_interval(encodings=['x', 'y'], bind='scales')

comparison = alt.Chart(df_comparison, title='Comparison').mark_point(filled=True).encode(
    alt.X('x1'),
    alt.Y('x2'),
).add_selection(x12_zoom)

signal_1 = alt.Chart(df_signal_1,title='Signal 1').mark_line().encode(
    alt.X('x1', scale=alt.Scale(domain={'selection': x12_zoom.name, 'encoding': 'x'})),
    alt.Y('data_1'),
)

signal_2 = alt.Chart(df_signal_2, title='Signal 2').mark_line().encode(
    alt.X('x2', scale=alt.Scale(domain={'selection': x12_zoom.name, 'encoding': 'y'})),
    alt.Y('data_2'),
)

(signal_1 & (comparison | signal_2))

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top