garrettj403 / SciencePlots

Matplotlib styles for scientific plotting
MIT License
7.12k stars 709 forks source link

findfont: Font family ['serif'] not found. Falling back to DejaVu Sans. #58

Closed iDTer closed 1 year ago

iDTer commented 2 years ago

os: win10 SciencePlots v1.0.9 matplotlib 3.3.0 python 3.8

I have put the NotoSerifSC fonts into "..\site-packages\matplotlib\mpl-data\fonts\ttf" and also try the following command: import matplotlib.font_manager as fm fm._rebuild()

but still report "findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.".

iDTer commented 2 years ago

Or how can I set the ['serif'] to ['sans serif']?

Thank you for any help!!!

G0K0URURI commented 2 years ago

This may be because you don't install the corresponding font.

I use matplotlib-3.5.2, and then meet similar problem with you:

findfont: Font family ['serif'] not found. Falling back to DejaVu Sans. 
findfont: Generic family 'serif' not found because none of the following families were found: Times

I solve the problem by install the needed font 'Times'. I download the .ttf file from https://www.dafontfree.net/times-regular/f145546.htm and copy it to 'my_python_path/site-packages/matplotlib/mpl-data/fonts/ttf/'. After that, I delete the cache of matplotlib, which could be found by

import matplotlib
matplotlib.get_cachedir()

I hope it would be helpful for you : )

hh-wu commented 2 years ago

You can use the following code to avoid warning in win10 without calling latex.

plt.style.use(['science', 'ieee', 'no-latex'])
matplotlib.rc('font', family='times new roman')
echedey-ls commented 1 year ago

Thank you everyone for the contribution. Closing as resolved, since no more reports of the problem were made, I assume it did work.