8

When I try and run, for example:

mpl.rcParams['font.family'] = 'serif'
plt.rcParams['figure.figsize'] = [15,7]
plt.plot(data['flow-time'], data['staticpressurerecovery'])
plt.xlabel('Time [s]')
plt.ylabel('Static Pressure Recovery [-]')
plt.title('McD13_4S3 Plenum: Performance Coefficient ')
plt.ylim((0.33, 0.4))
plt.grid()
plt.show()

in a Jupyter notebook, I get the following error message:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Things I've Tried:

  1. Deleting the fontList.cache, fontList.json, and fontList.py3.cache

  2. Uncommenting the font family related sections of the matplotlibrc file

  3. Uninstalled and reinstalled matplotlib using pip uninstall matplotlib and pip install matplotlib

Nothing has solved the issue. The only possible way for me to get different fonts now is to use LaTeX as the backend, but that's slow and unnecessary.

Any ideas what I can try next?

Edit: I'm using Windows 10, so not using apt-get for me. That seems to be a common fix for these problems, but I can't do it. It appears those solutions just add Microsoft fonts to the Linux font manager, so it's probably not even relevant since I'm already on a Microsoft machine.

Minimum working Example:

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['font.serif'] = 'Computer Modern'


t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.show()

In fontList.json, Computer Modern is listed as an available font.

4
  • 1
    That's sure a strange error because it should of course work (and does for me). I assume you did restart the kernel in between, right? So the first thing in such cases is always to produce a minimal reproducible example. In this case this would be 3 or 4 lines long and would be the only thing in your notebook. If this reproduces the error you can at least be sure that you did not do something strange in the remainder of the code. Sep 13, 2018 at 20:06
  • ImportanceOfBeingErnest I've updated the question with a working example. Problem has slightly changed now, but I still can't figure out why it's not working right. Sep 13, 2018 at 20:49
  • I think computer modern is a valid font set for mathtext.fontset, but at least my windows computer does not have computer modern as ttf font installed. Something like mpl.rcParams['font.serif'] = 'Times New Roman' should however work on any windows computer. Sep 13, 2018 at 21:31
  • I've added the 'Computer Modern' ttf to the data directory for matplotlib and those files are showing up in the fontsList.json file as well. Sep 14, 2018 at 16:52

1 Answer 1

0

I had the same issue. For me, changing my matplotlib version from back to 1.5.3 solves the issue. You need to pip uninstall matplotlib first then pip install matplotlib==1.5.3.

More context, I was using ggplot on zeppelin notebook with Amazon EC2. Somehow the matplotlib version installed was 2.2.3.

After changing the version, the error is gone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.