Reputation: 281
How to write greek letters in Altair? I need to use some symbols for the axis labels. I am using Jupyter notebook
Upvotes: 5
Views: 1790
Reputation: 73
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?
Upvotes: 2
Reputation: 22506
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'
)
Upvotes: 5