user19087
user19087

Reputation: 2063

shared interactive scales with 1D or tick plot

When a plot is either 1D or has tick marks, the domain is forced to include to origin. When I combine this plot with another 2D/non-tick plot, shared interactive scales don't work.

domain = alt.selection_interval(bind="scales", encodings=["x", "y"])

chart_1d =\
    ( alt.Chart(d1d)
    . mark_tick()
    . encode(x="values")
    . add_selection(domain)
    )

chart_2d =\
    ( alt.Chart(d2d)
    . mark_line()
    . encode(x="x", y="y")
    . add_selection(domain)
    )

chart = alt.vconcat(chart_1d, chart_2d)

I would like:

Upvotes: 2

Views: 77

Answers (1)

jakevdp
jakevdp

Reputation: 86330

One easy way to make this happen is to use the same field name for both x axes:

import altair as alt
import pandas as pd

d1d = pd.DataFrame({'x': [1, 2, 3, 4]})
d2d = pd.DataFrame({'x': [1, 2, 3, 4], 'y': [2, 3, 2, 3]})

domain = alt.selection_interval(bind="scales", encodings=["x", "y"])

chart_1d =\
    ( alt.Chart(d1d)
    . mark_tick()
    . encode(alt.X("x", title='values'))
    . add_selection(domain)
    )

chart_2d =\
    ( alt.Chart(d2d)
    . mark_line()
    . encode(x="x", y="y")
    . add_selection(domain)
    )

chart = alt.vconcat(chart_1d, chart_2d)

Upvotes: 1

Related Questions