Skip to content

Instantly share code, notes, and snippets.

@SHDShim
Last active October 3, 2023 01:08
Show Gist options
  • Save SHDShim/433c3668f43e10ce952b006b63f72cd5 to your computer and use it in GitHub Desktop.
Save SHDShim/433c3668f43e10ce952b006b63f72cd5 to your computer and use it in GitHub Desktop.
matplotlib, jupyter notebook, helvetica

How to setup helvetica font in matplotlib

Helvetica is the standard font for scientific plots. However, the default for matplotlib is not helvetica. You can use the following tutorial for making the change.

[Update in 2022/11/11]

Just have the following line in the beginning of a notebook will take care of the problem.

%config InlineBackend.figure_format='svg'
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'Helvetica'

https://github.com/olgabot/sciencemeetproductivity.tumblr.com/blob/master/posts/2012/11/how-to-set-helvetica-as-the-default-sans-serif-font-in.md

If you already have converted fonts

For conda:

cd ~/anaconda/lib/python3.5/site-packages/matplotlib/mpl-data/fonts/ttf

In this folder I have necessary helvetica fonts.

Go one above:

cd ..
open ttf

This will get you a finder window for the folder contents.

Then go to:

~/anaconda/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf

~/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf

Copy the following files from py3.5 to py3.6 ttf folder: Helvetica*.ttf

Then perform this:

rm ~/.matplotlib/fontList.py3k.cache

rm ~/.matplotlib/fontList.json

Also make sure you modify ~/.matplotlib/matplotlibrc for the following line:

font.sans-serif     : Helvetica, Lucida Grande, Verdana, Geneva, Lucid, Arial, Avant Garde, sans-serif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment