Python module to facilitate input in LaTex from Python scripts
Project description
Python to LaTeX
This is a module provides several method to parse data from Python to LaTeX.
Author:
- Sonja Stuedli
Installation
pip install --upgrade python_to_latex
Usage examples:
Below there are some small examples how to use the provided functions. Detailed explanation of each function can be found by using
import python_to_latex as p2l
help(p2l.<function_name>)
Printing a matrix:
import python_to_latex as p2l
import numpy as np
mat2lat(np.eye(2),matrix_style='bmatrix')
This will print the code block below and return the string to produce it.
\begin{bmatrix}
1 & 0\\
0 & 1\\
\end{bmatrix}
Printing table output:
import python_to_latex as p2l
numeric_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}
Saving a matplotlib figure:
import python_to_latex as p2l
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
x = np.arange(15)
y1 = 2*x
y2 = x+5
y3 = x
fig1,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)
The code above generates a simgle matplotlib figure and then saves that figure in PGF format in a file called test.tikz. The saved file can be loaded in LaTex.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python_to_latex-0.0.3.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for python_to_latex-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 179321fe407084674260319a2ac934df302c57394824246fa2ad86a10e146013 |
|
MD5 | 6080cd085846b9243242b951cfb98524 |
|
BLAKE2b-256 | 67ab6fe5e576410ff959b8ab7db99ba9dfc881c108157bf3ee761ac07e4b9f08 |