altair icon indicating copy to clipboard operation
altair copied to clipboard

Concatenation distorts interactive legend

Open lbittarello opened this issue 3 years ago • 2 comments

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

plot_1

However, if we change the last line to

alt.vconcat(scatter) | legend

we get

plot_2

This seems to be a regression – both plots look the same with Altair 4.1.0.

lbittarello avatar Mar 29 '22 08:03 lbittarello

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

jakevdp avatar Mar 29 '22 18:03 jakevdp

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)

joelostblom avatar Mar 29 '22 23:03 joelostblom

Fine for me too on development version. Closing seems fine then.

mattijn avatar Oct 29 '22 19:10 mattijn