My preferred font is Arial – it is tidy and generally easy to read. I generally like all my plots to look relatively similar. y-label): fig, ax = plt.plot(x,y) #some random variablesĪx.set_ylabel("First variable", fontname="Arial", fontsize=12) You should also be able to specify fonts directly on some figure portion (e.g. The above would make all plots in the notebook default to Comic Sans. Now, you should be able to specify a font in your notebook preamble as you wish: import matplotlib Now, any adjustments you want to make should be fairly straightforward! If you have conda installed I believe that it should be located in your home directory however, if you can’t find it there leave me a comment below. I found that I had to delete my cached matplotlib folder. We are almost done– but a few more steps just to make it work.
This will install and make those fonts available to you within your environment. While not totally comprehensive, it provides enough font variety for my purposes.Īfter having activated whatever environment you are using, you can install the mscorefonts package. These fonts include: Andale Mono, Arial, Arial Black, Comic Sans MS, Courier New, Georgia, Impact, Times New Roman, Trebuchet MS, Verdana, and Webdings. For the sake of demonstration my environment is called general_plotting.Ĭonveniently, there is a conda package mscorefonts that contains all the “core fonts” that are used for the Web. For the purposes of this tutorial, I will assume that you have created a conda environment that has matplotlib installed.
My remote HPC probably doesn’t have Microsoft fonts installed.Īs Arianna said (slacked, really) when I asked for her comments on this blog post: “This is because unlike an OS that we’re used to working with that’s all set up out-of-the-box, HPC admins don’t really have a need to use anything but some kind of Courier New.”Īnd so, I present to you… How to specify fonts in matplotlib when you are working on a Linux system:įirst off, I highly recommend using conda environments to manage research computational environments– it can enhance reproducibility and avoid package conflicts ( more here). I did this for… several years.Īnd then yesterday, I had an epiphany.
I figured I was simply doing something wrong and eventually gave up on trying to fix it and just succumbed to my fate of manually changing fonts post-plotting in Adobe Illustrator. Plt.rcParams = "sans-serif"Īnd also when I modified my matplotlibrc file (more on that later). This happened both when I directly specified the font in my notebook: import matplotlib.pyplot as plt I constantly got some variation of findfont: Font family not found. However, I could not get any of my font specifications to work in matplotlib (or any dependent programs) in my notebooks that I was running via ssh tunnel. This workflow is very convenient for many reasons (keeping all files in one location, more extensibility and power for my notebooks that my personal laptop can’t handle, minimizing file storage on my local machine, etc. Plt.Over the last few years I have made a transition in my workflow from doing most of my data exploration and plotting on my local machine (a 2016 MacBook laptop) to doing most of my plotting on a remote HPC (check out this other blog post for more on that). This answer didn't quite help me either : import matplotlib.pyplot as plt home/antoine/miniconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family not found. Prevent system exit right after the exec_() call Prevent deletion of objects in the local scope of functions leading to exec_() For clarity, this is what the pyzo kernel does: In most cases your app should run fine without the needįor modifications. The GUI event loop is already running in the pyzo kernel, and exec_()ĭoes not block. Plt.title('Please be Times >_> (executing file "") Trying as suggested in this question : import matplotlib.pyplot as plt Here comes the non-exhaustive list of what I've tried so far : So I've tried pretty much everything I could find on stackoverflow (and anywhere else google would lead me) and I just can't change the god damn font !