I’m trying to adjust the font weight in matplotlib, of a non-default font. However, for some reason the font weight doesn’t change when I use Avenir (.ttc font), Geneva (.ttf font), etc.
I’m running Mac OsX 14.5, Python 3.10, matplotlib 3.7.2.
I tested the default behavior and two other fonts:
fig, ax = plt.subplots(1,2)
ax[0].text(0.5,0.5, "Bla", weight = "normal", fontsize = 20)
ax[1].text(0.5,0.5, "Bla", weight = "heavy", fontsize = 20)
Default font:
Now, using non-default fonts:
font = {'family' : 'Avenir',
'weight' : 'normal',
'size' : 15}
plt.rc('font', **font)
fig, ax = plt.subplots(1,2)
ax[0].text(0.5,0.5, "Bla", weight = "normal", fontsize = 20)
ax[1].text(0.5,0.5, "Bla", weight = "heavy", fontsize = 20)
Avenir:
font = {'family' : 'Geneva',
'weight' : 'normal',
'size' : 15}
plt.rc('font', **font)
fig, ax = plt.subplots(1,2)
ax[0].text(0.5,0.5, "Bla", weight = "normal", fontsize = 20)
ax[1].text(0.5,0.5, "Bla", weight = "heavy", fontsize = 20)
Geneva:
I’m wondering if anybody knows why I’m getting this strange behavior and what I could do to fix it?
JBugg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.