Latex Formula Printing with Python

How to show light latex formula in python? Maybe numpy is the right choice?

EDIT:

I have python code like:

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

and want to print this on graphic output (e.g. matplotlib).

+12
python latex formula
source share
4 answers

As suggested by Andrew, work a little using matplotlib.

 import matplotlib.pyplot as plt a = '\\frac{a}{b}' #notice escaped slash plt.plot() plt.text(0.5, 0.5,'$%s$'%a) plt.show() 
+10
source share

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

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

(be sure to use $ , as in a regular streaming TeX!). r before the string means that no substitutions are performed; otherwise, you should avoid slashes as indicated.

More information on matplotlib .

+3
source share

No ticks:

 a = r'\frac{a}{b}' ax = plt.axes([0,0,0.1,0.2]) #left,bottom,width,height ax.set_xticks([]) ax.set_yticks([]) plt.text(0.3,0.4,'$%s$' %a,size=40) 
+1
source share

Draw using matplotlib,

 import matplotlib.pyplot as plt a = r'\frac{a}{b}' ax=plt.subplot(111) ax.text(0.5,0.5,r"$%s$" %(a),fontsize=30,color="green") plt.show() 

enter image description here

0
source share

All Articles