To match the font of my text in LaTeX, I want to use Nimbus Roman No9 L in matplotlib.
I check my LaTeX PDF and pdffonts returns:
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
SRVJHK+NimbusRomNo9L-Regu Type 1 Custom yes yes no 6 0
LXAKKR+NimbusSanL-Regu Type 1 Custom yes yes no 12 0
ZNRHEK+NimbusRomNo9L-ReguItal Type 1 Custom yes yes no 16 0
I thought it would be straightforward to switch fonts in matplotlib.
I attached a minimal example:
from matplotlib import pyplot as plt
plt.rcParams.update({
'font.family': 'serif',
'font.serif': 'Times New Roman', # 'Nimbus Roman No9 L',
})
plt.bar(['A ($1+1$)', 'B', 'C'], [1, 2, 3], align="center")
plt.savefig('minimal_example.pdf')
plt.show()
When I try to load Nimbus Roman No9 L I always get an error message:
WARNING:matplotlib.font_manager:findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.
WARNING:matplotlib.font_manager:findfont: Generic family 'serif' not found because none of the following families were found: Nimbus Roman No9 L
Times New Roman loads, but not for the $$ part.
> pdffonts minimal_example.pdf
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
TimesNewRomanPSMT Type 3 Custom yes no no 21 0
DejaVuSans Type 3 Custom yes no no 15 0
How can I use the same font in my plot as in my text?
edit:
I am able to load Nimbus Roman No9 L, it is called NimbusRomNo9L.
plt.rcParams.update({
'font.family': 'NimbusRomNo9L'
})
but the math formula still uses DejaVuSans
> pdffonts minimal_example.pdf
name type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
NimbusRomNo9L-Regu Type 3 Custom yes no no 14 0
DejaVuSans Type 3 Custom yes no no 28 0