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