How to use custom fonts in Matplotlib
After getting sick of the default font in matplotlib, and frankly annoyed by how difficult it seems to use custom fonts, Joses sat down and figured it out.These instructions below are for Mac OS X, and assume you have installed Jupyter.1. Install homebrew: go to and follow the instruction (no plural) herehttp://brew.sh/2. Install font converter fondu with homebrew using the command:brew install fonduin Terminal. We will used fondu to convert the font of choice to ‘ttf’.3. Then find the font file you want to add. Open FontBook in your Utilities folder, find your font of choice, right-click on it, and select “Show in Finder”.4. Copy the font family to the folder “”.5. If this font already has the file extension ttf, you can skip to step 6.If the font has file extension dfont, enter the following lines in Terminal:cd This will convert the .dfont file to a .ttf file.6. Now we need to delete the font cache for matplotlib. In terminal, enter the linescd ~/.matplotlibls -lto navigate to the matplotlib temp directory and list its contents.7. There should be a file named either fontList.cache or fontList.py3k.cache. Userm font.sans-serif and/or font.serif.Remove the’#’ at the beginning of these lines.11. Add the name of the font family to these lines. For example:font.serif : Alegreya, Droid Serif, Bitstream Vera Serif, …font.sans-serif : Helvetica Neue, Source Sans Pro, Bitstream Vera Sans…I have addedAlegreyaandDroidSerifto the serif family of fonts;HelveticaNeueandSourceSansProhave been added to the sans-serif family.Matplotlib will look for fonts in running order, so put the fonts you want to use as default immediately after the colon.11. Save the edited matplotlibrc file.12. Restart your Jupyter notebook and run the following lines.import matplotlib.pyplot as pltplt.rcParamsand scroll to the Font section again to check that your settings have taken effect.13. You can use the following matplotlib commands to change font family (sans-serif or serif) and the font. For example:plt.rcParams[‘font.family’] = ’serif’plt.rcParams[‘font.serif’] = ’Droid Serif’You’ll need to restart the notebook and run these lines again if you change the font.14. To ensure that your edited parameters file will not be ignored when using seaborn, you need to import seaborn asimport seaborn.apionly as snsThis is only possible with the latest version of seaborn (v0.7.1).-Joses Ho