Mettre des formules mathématiques LaTeX avec Matplotlib

Exemple d'équation mathématiques avec LaTeX et matplotlib
Exemple d'équation mathématiques avec LaTeX et matplotlib

#!/usr/bin/env python

from pylab import *

t = arange(-6.0, 4.0, 0.01)
s= t*t*t/4.0+3.0*t*t/4.0-3*t/2.0-2.0

ax = subplot(111)
ax.plot(t, s,'r-')
ax.grid(True)
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
ax.set_xlim(-6,6)
ax.set_ylim(-20,20)

text(6.5, -0.5, r'x')
text(-0.0, 21.5, r'y')

text(-3.5, 12,
     r"$f(x)=\frac{X^3}{4}+\frac{3.X^2}{4}-\frac{3.X}{2}-2$", 
     horizontalalignment='center',
     fontsize=17)

plt.savefig('latexetmatplotlib.png')
show()
Image

of