Sexy Fonts on the Cluster

using Latin Roman locally with matplotlib

I like making plots with Latin Roman, a successor font of Computer Modern which has pleasing serifs and more importantly, looks like the default LaTeX font for many journals. You can't install fonts and then refresh the font-cache on the cluster though, since most users don't have sudo access. Here's a way to install Latin Roman for just matplotlib inside your conda environment.

An example of this font in use

First, download the fonts.

wget http://mirrors.ctan.org/fonts/lm.zip
unzip lm.zip

Next, activate your Anaconda environment of choice and copy the fonts into Matplotlib. This assumes your Anaconda distribution stores data in the default location ~/.conda.

cp lm/fonts/opentype/public/lm/* ~/.conda/envs/$CONDA_DEFAULT_ENV/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf

Next, refresh matplotlib's font cache.

python -c "import matplotlib.font_manager as fm; fm._rebuild()"

Finally, we can delete those temporary font files.

rm -rf lm lm.zip