使用 Altair 和 Jupyter 绘图时如何在轴标签中显示希腊字母?

Yit*_*iti 5 python latex jupyter altair

如何在 Altair 中写希腊字母?我需要为轴标签使用一些符号。我正在使用 Jupyter 笔记本

Ram*_*han 5

您可以使用轴中所需符号的希腊语 Unicode在轴中显示希腊字母。

工作示例:

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'
)
Run Code Online (Sandbox Code Playgroud)

它产生: 带有希腊字符的 x 轴绘图