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.