Monday, February 8, 2016

Changing font in matplotlib

In order to change the font of text in a matplotlib figure, I needed a list of the available fonts. It took me a frustratingly long time to find this stack exchange answer, so I thought I would record the solution here.

import matplotlib.font_manager
{ for f in matplotlib.font_manager.fontManager.ttflist}

Then just choose a name from the set and insert it into a text command, e.g.

import matplotlib.pyplot as plt
plt.title('title', fontname='FreeSans')

No comments: