For the sake of consistency, I would like to make sure that all my Altair charts use the same font as Streamlit – IBM Plex Sans
.
As far as I can tell, the expected way to do that is via Altair themes:
- https://github.com/altair-viz/altair/issues/1325
- https://altair-viz.github.io/user_guide/configuration.html?highlight=theme#altair-themes
So here is my code:
def streamlit_theme():
font = "'IBM Plex Sans', sans-serif"
return {
"config": {
"title": {"font": font},
"axis": {"labelFont": font, "titleFont": font},
"header": {"labelFont": font, "titleFont": font},
"legend": {"labelFont": font, "titleFont": font},
}
}
alt.themes.register("streamlit_theme", streamlit_theme)
alt.themes.enable("streamlit_theme")
While the font does change correctly to IBM Plex Sans
, the bad news is that my charts are now squashed. Look at their aspect ratios before and after:
-
Before
-
After
Am I doing anything wrong? Any insights about how to fix this?