views:

54

answers:

3

Hello!

I search the whole time but cannot find it. How to show an easy latex-formula in python? Maybe numpy is the right choice?

EDIT:

I have a python code like:

a = '\frac{a}{b}'

and want to print this in a graphical output (like matplotlib).

+1  A: 

Matplotlib can already do TeX, by setting text.usetex: True in ~/.matplotlib/matplotlibrc. Then, you can just use TeX in all displayed strings, e.g.,

ylabel(r"Temperature (K) [fixed $\beta=2$]")

(be sure to use the $ as in normal in-line TeX!). The r before the string means that no substitutions are made; otherwise you have to escape the slashes as mentioned.

More info at the matplotlib site.

Andrew Jaffe
Is matplotlibrc in the matplotlib-folder? I cant find it :/
kame
On UNIX systems, it's in the directory I mention above. On windows, I don't know. Check the Docs.
Andrew Jaffe
A: 

See the docs on the matplotlib site:

ars
Very strange things happen when I run the example code. The shell open and closes the whole time. Matplotlib and Tex is installed.
kame
+2  A: 

As suggested by Andrew little work around using matplotlib.

import matplotlib.pyplot as plt
a = '\\frac{a}{b}'  #notice escaped slash
plt.plot;plt.text(0.5,0.5,'$%s$'%a)
Bernardo Kyotoku
Nothing happend. I installed matplotlib.
kame
i forget: plt.show()
kame