Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > bf21b4394f4d7fa09e3626145d3315e0 > files > 498

python-matplotlib-doc-1.2.0-14.fc18.i686.rpm

.. _pylab_examples-tex_demo:

pylab_examples example code: tex_demo.py
========================================



.. plot:: /builddir/build/BUILD/matplotlib-1.2.0/doc/mpl_examples/pylab_examples/tex_demo.py

::

    #!/usr/bin/env python
    """
    You can use TeX to render all of your matplotlib text if the rc
    parameter text.usetex is set.  This works currently on the agg and ps
    backends, and requires that you have tex and the other dependencies
    described at http://matplotlib.sf.net/matplotlib.texmanager.html
    properly installed on your system.  The first time you run a script
    you will see a lot of output from tex and associated tools.  The next
    time, the run may be silent, as a lot of the information is cached in
    ~/.tex.cache
    
    """
    from matplotlib import rc
    from numpy import arange, cos, pi
    from matplotlib.pyplot import figure, axes, plot, xlabel, ylabel, title, \
         grid, savefig, show
    
    
    rc('text', usetex=True)
    rc('font', family='serif')
    figure(1, figsize=(6,4))
    ax = axes([0.1, 0.1, 0.8, 0.7])
    t = arange(0.0, 1.0+0.01, 0.01)
    s = cos(2*2*pi*t)+2
    plot(t, s)
    
    xlabel(r'\textbf{time (s)}')
    ylabel(r'\textit{voltage (mV)}',fontsize=16)
    title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
          fontsize=16, color='r')
    grid(True)
    savefig('tex_demo')
    show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)