How to write greek letters in Altair? I need to use some symbols for the axis labels. I am using Jupyter notebook
Asked
Active
Viewed 1,581 times
2 Answers
5
You can display Greek letters in your axis by using the Greek Unicode of the symbols you want in your axis.
Working example:
import altair as alt
from vega_datasets import data
unicode_gamma = '\u03b3'
# for the notebook only (not for JupyterLab) run this command once per session
alt.renderers.enable('notebook')
iris = data.iris()
alt.Chart(iris).mark_point().encode(
x=alt.X('petalLength', axis=alt.Axis(title=' Alpha Beta Gamma \u03b1 \u03b2 '+ unicode_gamma)),
y='petalWidth',
color='species'
)

Ram Narasimhan
- 22,341
- 5
- 49
- 55
2
Altair doesn't support Latex math like matplotlib because only Unicode characters are supported in Vega.
I encountered the same issue yesterday when I tried to convert my old plots generated using matplotlib to Altair, and the labels/title didn't display properly. The answer above is great, just want to add that, some common superscripts/subscripts also have their unicodes that can be passed into Altair/Vega.
Check this wonderful answer: How to find the unicode of the subscript alphabet?

Yu Cheng
- 73
- 1
- 8