## matplotlib-users

 [Matplotlib-users] mathtext in legend ? From: Nils Wagner - 2006-06-08 11:48:22 Hi all, Can I use formulas within the legend command, e.g. legend( ('$\sin(x)$', '$\cos(x)$'), loc='upper left') Nils
 Re: [Matplotlib-users] mathtext in legend ? From: John Hunter - 2006-06-09 13:26:28 >>>>> "Nils" == Nils Wagner writes: Nils> Hi all, Can I use formulas within the legend command, e.g. Nils> legend( ('$\sin(x)$', '$\cos(x)$'), loc='upper left') You can, but there are two problems with your example. One, you need to be using "raw" strings if you are using single backslashes, eg r'$\sin(x)$' the other is that mathtext doesn't recognize \sin, \cos, \exp etc. (Edin are you out there? If so, this would be something useful to work on). You can do the equivalent by setting the font to roman from pylab import figure, show, nx x = nx.arange(0.0, 1.0, 0.01) fig = figure() ax = fig.add_subplot(111) ax.plot(x, nx.sin(2*nx.pi*x), 'ro', label=r'$\rm{sin}(x)$') ax.plot(x, nx.cos(2*nx.pi*x), 'gs', label=r'$\rm{cos}(x)$') ax.legend(loc='upper center') show() but unfortunately the layout is crappy. This is one of the things Edin will be working on this summer, trying to fix the kerning (by using a better set of fonts) so the spacing in '(x)' is handled properly. If you have access to TeX, dvipng and ghostscript, you can use "usetext" for better layout. JDH
 Re: [Matplotlib-users] mathtext in legend ? From: - 2006-06-10 07:47:35 On 6/9/06, John Hunter wrote: > the other is that mathtext doesn't recognize \sin, \cos, \exp etc. > (Edin are you out there? If so, this would be something useful to > work on). Yes, I'm alive and well, thank you :). It's on my radar now.