vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.4k stars 795 forks source link

JupyterChart dark theme with vegafusion datatransformer #3677

Open Jhsmit opened 2 weeks ago

Jhsmit commented 2 weeks ago

What happened?

I'm trying to make a JupyterChart in dark theme with the vegafusion transformed enabled. code:

df = pl.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
chart = alt.Chart(df).mark_point().encode(x="x",y="y")

with default transformer: Image

with vegafusion: Image

When I click "Open in Vega Editor" I see the same behavior, so my reasoning was therefore the vega-lite spec generated has a bug and the issue should be reported here.

What would you like to happen instead?

Expected behavior is the graph to look the same as with the default transformer

Which version of Altair are you using?

5.4.1

jonmmease commented 2 weeks ago

Hi @Jhsmit, could you try applying the theme with alt.themes.enable following Changing the Theme docs?

What's happening is that the VegaFusion data transformer converts the Vega-Lite spec to Vega using vl-convert in Python (because VegaFusion operates on Vega specifications) and this Vega specification is what is sent to the browser for display. But Vega-Embed themes (supplied to embed_options) are applied only in the browser at display time, and they only apply to Vega-Lite charts (not Vega). By using alt.themes.enable, the theme gets applied in Python before the conversion to Vega.

All that said, I think it would make sense for us to look for a theme in embed_options when VegaFusion is enabled and do this automatically.

Jhsmit commented 2 weeks ago

That works! thanks also works without embed options

alt.themes.enable('dark')
alt.data_transformers.enable("vegafusion")
alt.JupyterChart(chart)

Image