I’m trying to set the font for plots in matplotlib using rcParams:
mp.rc('font', family = 'sans-serif') # 'Arial' # font group is sans-serif
mp.rcParams["font.sans-serif"] = ["Arial"]
When deployed, I receive the following errors:
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Generic family 'sans-serif' not found because none of the following families were found: Arial
I tried runnin st.write(plt.rcParams["font.sans-serif"][:]) , which returns the following list:
"Bitstream Vera Sans",
"Computer Modern Sans Serif",
"Lucida Grande",
"Verdana",
"Geneva",
"Lucid",
"Arial",
"Helvetica",
"Avant Garde",
"sans-serif"]
How should I get matplotlib to import fonts correctly? I couldn’t find any similar issues.
Thank you, at least I understand why this is an issue now! I tried using apt-get to install ttf-mscorefonts-install, which also could not be found
I’m not sure if other font options are installed onto the streamlit cloud then. As far as I can tell the only font available is the default (DejaVu Sans). For my specific purposes, I could use another sans serif font, but not DejaVu Sans. I guess I could try installing Arial from a .ttf file in the repo itself
No luck on Liberation Sans, since mp.rcParams["font.sans-serif"] = "Liberation Sans" returns
findfont: Generic family 'sans-serif' not found because none of the following families were found: Liberation Sans
Also could not install Microsoft fonts, since I get the error
Package ttf-mscorefonts-installer is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'ttf-mscorefonts-installer' has no installation candidate
Thank you so much! This worked great. It was also super helpful that you linked the Debian package list, which I hadn’t seen previously. For anyone else who would like to substitute, there is a helpful list of stable Debian fonts packages. I think all of these should be installable by adding their names to packages.txt. You can then set the matplotlib font as usual,
The list includes font support for other languages, which for some applications might work and is easier than other solutions I had seen to actually install .ttf files through either mp.font_manager or Path.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.