How to write greek letters in Altair? I need to use some symbols for the axis labels. I am using Jupyter notebook
To use them you simply type \Alpha then hit tab and there you have an α character. This is pretty simple, and not only does it work in markdown cells but it also works within code cells as well. The complete Greek alphabet can be seen here, along with a little history about it.
To print any character in the Python interpreter, use a \u to denote a unicode character and then follow with the character code. For instance, the code for β is 03B2, so to print β the command is print('\u03B2') .
You can already use Greek letter variable names in Python: https://stackoverflow... | Hacker News.
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'
)
which produces:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With