# change legend font when plotting

I would like to ask are there any ways to change the font of the legend? I searched the document and only found the option "legend_font_family", which can be sans-serif, serif or other name. However, I don't want to use the default font defined in system.

edit retag close merge delete

1

legend handling is done in the .matplotlib method of Graphics objects; you can see the source code at http://hg.sagemath.org/sage-main/file/c239be1054e0/sage/plot/plot.py#l2009 To use a different font, I guess you'll have to see how matplot lib gets its font.

( 2012-04-13 01:48:33 -0500 )edit

Sort by » oldest newest most voted

This is the header I use to make plots. I use Computer Modern Roman because it matches with the Latex document font. You can switch on the usetex switch if you want to give complicated Latex commands in the legend. It is not necessary most of the time, but does no harm either.

from matplotlib import rc
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
#plt.rc('text', usetex=True)
plt.rc('font',**{'family':'serif','serif':['Computer Modern Roman'],'size':12})

more

## Stats

Seen: 1,693 times

Last updated: Apr 13 '12