Python模块,方便从Python脚本输入到LaTex中
python-to-latex的Python项目详细描述
Python到乳胶
这个模块提供了几种将数据从Python解析到LaTeX的方法。在
作者:
- 索尼娅·斯图德利
安装
pip install --upgrade python_to_latex
使用示例:
下面是一些如何使用提供的函数的小例子。每个功能的详细说明可以通过使用
import python_to_latex as p2l
help(p2l.<function_name>)
打印矩阵:
^{pr2}$这将打印下面的代码块并返回字符串以生成它。在
\begin{bmatrix} 1 & 0\\ 0 & 1\\\end{bmatrix}
打印表输出:
importpython_to_latexasp2lnumeric_list_to_tabularx([[1,2,3],[4,5,6]],heading=['A','B','c'])
The above code will print the code block below and return the string to produce it.
\begin{tabularx}{\linewidth}{S[table-auto-round,table-omit-exponent,fixed-exponent=0]S[table-auto-round,table-omit-exponent,fixed-exponent=0]S[table-auto-round,table-omit-exponent,fixed-exponent=0]}\toprule{A}&{B}&{C}\\\midrule 1 & 2 & 3\\ 4 & 5 & 6\\\bottomrule\end{tabularx}
保存matplotlib图形:
importpython_to_latexasp2limportnumpyasnpimportmatplotlibimportmatplotlib.pyplotaspltx=np.arange(15)y1=2*xy2=x+5y3=xfig1,plt1=plt.subplots(nrows=1,ncols=2)plt1[0].plot(x,y1)plt1[0].plot(x,y2,'.',label="line a")plt1[1].plot(x,y3,label="line 1")plt1[0].set_ylabel('$\lambda_2$')plt1[1].set_xlabel('$b$')plt1[1].set_ylabel('$\lambda_N$')plt1[1].set_xlabel('$N$')plt1[0].legend(loc=1)plt1[0].set_label("test")fig1.show()fig2pgf(fig1,"test",retain_color=True,retain_linestyle=True)
上面的代码生成一个simgle matplotlib图形,然后将该图形以PGF格式保存在一个名为测试.tikz. 保存的文件可以在LaTex中加载。在
- 项目
标签: