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