Ask Your Question

change legend font when plotting

asked 2012-04-12 19:02:39 -0500

lainme gravatar image

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 flag offensive close merge delete



legend handling is done in the .matplotlib method of Graphics objects; you can see the source code at To use a different font, I guess you'll have to see how matplot lib gets its font.

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

1 answer

Sort by ยป oldest newest most voted

answered 2012-04-13 18:02:44 -0500

Shashank gravatar image

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})
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-04-12 19:02:39 -0500

Seen: 1,620 times

Last updated: Apr 13 '12