altair
altair copied to clipboard
Concatenation distorts interactive legend
Sorry if this issue has been reported before!
Consider this example from the documentation:
import altair as alt
from vega_datasets import data
cars = data.cars.url
selection = alt.selection_multi(fields=["Origin"])
color = alt.condition(
selection, alt.Color("Origin:N", legend=None), alt.value("lightgray")
)
scatter = (
alt.Chart(cars)
.mark_point()
.encode(x="Horsepower:Q", y="Miles_per_Gallon:Q", color=color, tooltip="Name:N")
)
legend = (
alt.Chart(cars)
.mark_point()
.encode(y=alt.Y("Origin:N", axis=alt.Axis(orient="right")), color=color)
.add_selection(selection)
)
scatter | legend
produces

However, if we change the last line to
alt.vconcat(scatter) | legend
we get

This seems to be a regression – both plots look the same with Altair 4.1.0.
Thanks for the report! It seems to be a change in Vega-Lite's default layout. I'm not sure whether it's a bug or intended behavior in the vega-lite renderer
This is working for me as expected when installing Altair directly from the GitHub repos main branch so it must have been fixed in later versions of VL although I did find a few issues that seem related:
- https://github.com/vega/vega-lite/pull/6226
- https://github.com/vega/vega-lite/pull/6095
- https://github.com/vega/vega-lite/issues/6209
- https://github.com/vega/vega-lite/issues/6277 (open)
Fine for me too on development version. Closing seems fine then.