0

I'm trying to have my text labels in matplotlib all be an Arial font. Taking from here, I tried the following:

plt.rcParams['mathtext.it'] = 'Arial:italic'
plt.rcParams['mathtext.rm'] = 'Arial'
plt.rcParams['mathtext.default'] = 'regular'
plt.rcParams['font.serif'] = 'Arial'
plt.rcParams['font.family'] = 'Arial'

This solves the problem in nearly every single case. The problem comes up when I try to put on a plot label that contains both italic and regular font. There, when I try the following:

label_name = r'$\mathit{%s}$ %s' % (gene, splice)
ax1c.set_ylabel(label_name, fontsize=8, labelpad=17)

The font ends up not being an Arial. I get the same when I try r'$\it{%s} $ %s' % (gene, splice) as well. I have tried both of the following two lines of code:

plt.rcParams['mathtext.fontset'] = 'custom'
mpl.rcParams['mathtext.fontset'] = 'custom'

however, neither works, and both return the following error:

/home/soma/anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1320: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))

The best link I have found for fixing this problem was here. I have tried the following:

  • Quit Jupyter
  • sudo apt install font-manager
  • sudo apt install msttcorefonts -qq
  • rm ~/.cache/matplotlib -rf
  • restart Jupyter

however I continue to get the same error.

I would appreciate either an alternative to the rcParams['mathtext.fontset'] = 'custom' solution, or a solution tot he font not found problem

David L
  • 441
  • 3
  • 9
  • I can't reproduce your font problem, but I don't use Jupyter. It might be a good idea to include version numbers for Python, matplotlib and Jupyter. And a picture that shows, what kind of font the system chooses instead of Arial. – Mr. T May 24 '18 at 13:36
  • Jupiter 3.5.11, python3.6.4 :: Anaconda, Inc., and matplotlib 2.1.2. I can't post a picture since the plot itself since it is for my paper, and I can't make a new one since the problem somehow fixed itself overnight. As in last night when I left work it existed, and today morning the exact same code, from the exact same notebook (I shut down neither the computer, jupypter or the notebook after leaving work) uses Arial now. The UserWarning still exists, but the code is fine (well, beyond it only putting letters, not numbers in italics). I'm honestly not sure what to think... – David L May 25 '18 at 06:31

0 Answers0