Hi, we're using our own theme (config) for our charts using vega - if I understand correctly it can be done through the altair by using Chart.configure() for each chart.
What I am proposing is to add single method like
import altair as alt
altair.configure() # or altair.defaults()
so that we won't need to patch every single chart.
I will be happy to PR (sounds trivial), if you think this is a good idea
Hi,
There is a way to do this already, but it's not well documented because there are not really any default themes available.
You can specify, register, and enable themes like this:
def my_theme():
return {'config': {'background': 'black'}}
alt.themes.register('my_theme', my_theme)
alt.themes.enable('my_theme')
Once a theme is enabled, it will be used for every chart you create.
I'll leave this issue open as a reminder that we should document this feature.
ah, got it, thanks!
it would be probably nice to add just a little bit on top of that
alt.set_theme('ggplot')
alt.set_theme({'config': {'background': 'black'}})
Yes, the plan is to have custom named themes available, but they are still being developed (which is why this mechanism is not documented yet).
It will look like alt.themes.enable('dark') or similar.
We also plan to make available all the themes here: https://github.com/vega/vega-themes
But it will take a bit of thinking to figure out how to make things transparent to the user.
Probably Charts can propagate default configs on initialization so that config can be changed manually after? Plus, config will be part of resulting vegalite/vega json specs in this - that sounds pretty transparent to me...
Anyway, thanks for the help!
Let me know if I can somehow help with that (or any other python-side issues on altair, for that matter).
By "transparent" I meant that I don't want users to have to think about the presence of the vega-themes repository, or whether they're using a theme defined there or one defined elsewhere. It's tricky because vega-themes are specified via metadata passed to vega-embed, while other themes are specified by modifying the actual chart specification.
It's doable, it just will take some thought to implement well.
Can this be closed since https://github.com/altair-viz/altair/pull/900/ was merged or is this open for more docs to be added?
Most helpful comment
It's doable, it just will take some thought to implement well.