【问题标题】:How to display Greek letters in Axis labels when plotting with Altair and Jupyter?使用 Altair 和 Jupyter 绘图时如何在轴标签中显示希腊字母?
【发布时间】:2018-04-30 12:25:05
【问题描述】:

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

【问题讨论】:

    标签: python latex jupyter altair


    【解决方案1】:

    您可以在坐标轴中显示希腊字母,方法是使用坐标轴中所需符号的Greek 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'
    )
    

    产生:

    【讨论】:

      【解决方案2】:

      Altair 不支持像 matplotlib 这样的 Latex 数学,因为 Vega 仅支持 Unicode 字符。

      昨天我尝试将使用 matplotlib 生成的旧图转换为 Altair 时遇到了同样的问题,并且标签/标题没有正确显示。上面的答案很好,只是想补充一点,一些常见的上标/下标也有可以传递到 Altair/Vega 的 unicode。

      查看这个精彩的答案:How to find the unicode of the subscript alphabet?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-22
        • 1970-01-01
        • 2015-08-10
        • 1970-01-01
        相关资源
        最近更新 更多