Using Unicode fonts

Hi,

I need to use some unicode text in my plots (Devanagari - Marathi). Locally the font manager finds the font. How do I do that in the streamlit app? Do I include the ttf file? Or add something to the requirements file? How? I am not using anything non-standard here otherwise. Below is the code snippet that uses the ‘Sanskrit 2003’ font, and the deployed version is here:
https://share.streamlit.io/ashishmahabal/lamal/main/lamal.py

lamalarts[‘Topic’].value_counts()[:10].sort_values().plot(kind=“barh”)
for tick in ax.get_yticklabels():
tick.set_fontname(“Sanskrit 2003”)

Thank you for the help.

-ashish

Hello @AshishMahabal, welcome to the community!

If you’re using a custom font into Matplotlib, my guess would be to include a folder with the .ttf file to your Github project, then set up a custom font for matplotlib from inside your app.

I haven’t tested it but I hope it puts you on the right track :slight_smile: I’d be happy to hear back from you when you got it working.

Cheers,
Fanilo

1 Like

Thank you, @andfanilo. That worked.

I used tick.set_fontname(“Kalam”) for it to work in a specific location rather than setting it explicitly for the entire script using rcParams.

It is devanagari font, and it does not render the glyphs correctly right now, but that is a completely separate question.

Thanks, again!

-ashish

1 Like

Hi, I am facing kind of the same issue. I like to use a specific font (chewy) in my streamlit web app (suvat_calculator/suvat_calculator_en.py at main · rafisics/suvat_calculator · GitHub). I have done the following:

st.markdown("<div><h1 style='text-align: center; color: #ff7903; font-family: Chewy'> SUVAT Calculator </h1></div>", unsafe_allow_html=True)

I can see the font because it’s installed on my computer. But I want it to appear to the users of the app who might not have it installed. How can I do that?