Ask Your Question
1

change legend font when plotting

asked 2012-04-13 02:02:39 +0200

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

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 ( 2012-04-13 08:48:33 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-04-14 01:02:44 +0200

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

Stats

Asked: 2012-04-13 02:02:39 +0200

Seen: 2,388 times

Last updated: Apr 14 '12