Ask Your Question
1

change legend font when plotting

asked 12 years ago

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.

Preview: (hide)

Comments

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.

niles gravatar imageniles ( 12 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 12 years ago

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})
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 2,509 times

Last updated: Apr 14 '12