Altair: How to type Math Symbol into labels or title?

Created on 21 Aug 2018  路  4Comments  路  Source: altair-viz/altair

import altair as alt
import pandas as pd
import numpy as np

# Create a selection that chooses the nearest point & selects based on x-value
nearest = alt.selection(type='single', nearest=True, on='mouseover',
                        fields=['Time'], empty='none')

# The basic line
line = alt.Chart().mark_line(interpolate='basis',color='#333').encode(
    x=alt.X('Time:T',axis=alt.Axis(title='Date')),
    y=alt.Y('PM25:Q',axis=alt.Axis(title='PM2.5 (渭g/m3)'))
)

I tried putting the unit to my y-axis label. Coming from matplotlib I first tried y=alt.Y('PM25:Q',axis=alt.Axis(title=r'PM2.5 $(\mu g/m^{3})$')). For now I used Jupyter notebook to type 渭 but still didn't figure out how to type the power. I searched through the documentation but didn't find a solution.

Please help me out if there is a way to do it. Thank you!

enhancement vega-lite-related

Most helpful comment

Only Unicode characters are supported in Vega. Meaning that rendering of LaTeX text and MathJax is not supported in Altair

You can search for the corresponding superscript character at this page:
https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts and copy the character of interest in your specification.

Maybe Altair could implement a preprocessing feature that convert defined MathJax to Unicode characters.

All 4 comments

Only Unicode characters are supported in Vega. Meaning that rendering of LaTeX text and MathJax is not supported in Altair

You can search for the corresponding superscript character at this page:
https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts and copy the character of interest in your specification.

Maybe Altair could implement a preprocessing feature that convert defined MathJax to Unicode characters.

Thanks for replying. I was suspecting that too, so I looked into the documentation of Vega-lite/Vega. That converter idea is worth a try, it probably will help more matplotlib users to convert to Altair.
I found this great answer on Stackoverflow for unicode super/subscripts of common powers and greek alphabets: https://stackoverflow.com/questions/17908593/how-to-find-the-unicode-of-the-subscript-alphabet

+1 for using math / latex in the titles. I was trying to figure out how to display a fraction nicely but it doesn't seem to be possible.

The relevant Vega feature request is here: https://github.com/vega/vega/issues/898

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmcfee picture bmcfee  路  3Comments

dzonimn picture dzonimn  路  3Comments

LukeMathWalker picture LukeMathWalker  路  3Comments

HalukaMB picture HalukaMB  路  3Comments

nielsmde picture nielsmde  路  4Comments