Matplotlib Fonts (plots, basemaps, etc.)

Here is the trick (well documented on the matplotlib webpage) to define the font family and size of what appears on your matplotlib plot:

Before calling anything related to matplotlib in your script, do:

### rcParams are the default parameters for matplotlib
import matplotlib as mpl
mpl.rcParams['font.size'] = 10.
mpl.rcParams['font.family'] = 'Comic Sans MS'
mpl.rcParams['axes.labelsize'] = 8.
mpl.rcParams['xtick.labelsize'] = 6.
mpl.rcParams['ytick.labelsize'] = 6.

Calling these lines before creating a basemap plot will also work !

Note: you can permanently define the default values if you *really* prefer Comic Sans Ms for all your plots, e.g. The matplotlibrc file is located somewhere on your disk, to know where, just type:

import matplotlib
print matplotlib.matplotlib_fname()

gives : “c:\Python26\lib\site-packages\matplotlib\mpl-data\matplotlibrc”

which starts with :

### MATPLOTLIBRC FORMAT

# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc.  If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).

Quite easy to understand, isn’t it ?

More information about Customizing Matplotlib can be found here.

One thought on “Matplotlib Fonts (plots, basemaps, etc.)

  1. Pingback: Tweets that mention Matplotlib Fonts (plots, basemaps, etc.) - Géophysique.be -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*