0

Following the accepted answer of this thread, I'm trying to use the following MinionPro-Regular otf font installed on my Windows 10 machine

enter image description here

to set the fonts of all texts and math expressions of my plot to that font as follows.

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

mpl.rcParams['font.family'] = 'MinionPro-Regular'
mpl.rc('text', usetex='true') 
mpl.rc('text.latex', preamble=r'\usepackage{bm}')

x = np.arange(0,2*np.pi,0.1)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x,y, label ='Exact')
ax.set_xlabel(r"$\bm{x}$", fontsize=20)
ax.xaxis.label.set_color('red')
ax.set_ylabel(r"$\bm{y}$", fontsize=20)
ax.yaxis.label.set_color('red')
ax.set_title("My title", size=20)

plt.legend()
plt.show()

However, I get the error below:

findfont: Font family ['MinionPro-Regular'] not found. Falling back to DejaVu Sans.

Any idea regarding this problem?

Edit: if I use mpl.rcParams['font.family'] = 'Minion Pro', there is no error, however the font is still not Minion Pro like:

enter image description here

User
  • 952
  • 2
  • 21
  • 43
  • Have you tried just `"Minion Pro"` instead? IIRC, matplotlib's `font.family` takes the names of fonts (like you'd see in the font dropdown menu in Word or Excel or something), not the name of the font file, which could be anything. – MattDMo Aug 13 '21 at 16:36
  • @MattDMo: As you may check the edit, using `"Minion Pro"` for `font.family` removes the error , but the returned plot's font is still not Minion Pro. – User Aug 13 '21 at 16:52

1 Answers1

1

Check out site-packages/matplotlib/mpl-data/matplotlibrc. Apparently, font.family is "not supported when rendering text with usetex".

From the text.usetex documentation,

"The following fonts are supported through the usual rc parameter settings: new century schoolbook, bookman, times, palatino, zapf chancery, charter, serif, sans-serif, helvetica, avant garde, courier, monospace, computer modern roman, computer modern sans serif, computer modern typewriter. If another font is desired which can loaded using the LaTeX \usepackage command, please inquire at the Matplotlib mailing list".

MattDMo
  • 100,794
  • 21
  • 241
  • 231