I want to change the font and the size of one of the labels of a pie chart. The font is called 'Berkelium Type' and according to the fontList.cache file in my .matplotlib directory Matplotlib could load it.
The code is
import matplotlib.pyplot as plt
count = (1., 2., 3.)
labels = ('Text1', 'Text2', 'Text3')
pie = plt.pie(count, labels=labels)
pie[1][0].set_fontsize(24)
pie[1][0].set_family('Berkelium Type')
plt.axis('equal')
plt.draw()
plt.show()
Changing the font size worked so far. However, it did not change the font itself.
I did a test with a simple text
test = plt.text(0.5, 0.5, 'This is a test.')
Neither
test.set_family('serif')
nor
test.set_family('sans-serif')
has any effect on the text.
So I'm wondering if I'm doing something conceptionally wrong here. Is this the right approach to change the font of a text?
Update:
I did exactly what this post is suggesting:
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(10))
prop = fm.FontProperties(fname='/home/sebastian/.local/share/font/kkberktp.ttf')
ax.set_title('This is some random font', fontproperties=prop, size=32)
plt.show()
As a result I get this:
This is not the font I've chosen.
Could there be anything that is overwriting my font settings?
The font is available here.