A Docker and AWS utility package
Project description
Matplotlib2LaTeX
An high-level python library to have your plots in pgf, the perfect format for an awesome LaTeX report/publication. The documentation is available at this link
Sometimes there may be an error about the a matplotlib lockfile. Just restart the kernel.
Installation
To install simply run
pip install mpl2latex
it requires matplotlib to work.
Example of use on jupyter notebook
First, we import numpy, matplotlib and the new library MPL2LATEX. We will then make some examples with different type of implementation
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from mpl2latex import Matplotlib2LaTeX, latex_figsize
We will plot some simple data, let's say a quadratic function
x = np.linspace(1, 100, 1000)
fig, ax = plt.subplots(figsize=latex_figsize( wf=0.8) ) # width of an entire latex column
ax.plot(x, x**2)
ax.set_xlabel('x')
ax.set_ylabel('$x^2$')
ax.set_title('Trial')
plt.show()
Now, we make the same but with the parameters of Matplotlib2LaTeX, using it from the start
fig, ax = plt.subplots(figsize=latex_figsize( wf=0.8) ) # width of an entire latex column
ltx = Matplotlib2LaTeX(fig)
ltx.ax[0].plot(x, x**2)
ltx.ax[0].set_xlabel('x')
ltx.ax[0].set_ylabel('$x^2$')
ltx.ax[0].set_title('Trial')
ltx.show()
We can easily come back to the default settings for matplolib
ltx.reset()
fig, ax = plt.subplots(figsize=latex_figsize( wf=0.8) ) # width of an entire latex column
ax.plot(x, x**2)
ax.set_xlabel('x')
ax.set_ylabel('$x^2$')
ax.set_title('Trial')
plt.show()
But we can also save the figure in pgf and then we automatically come back to our usual backend to visualize the plots in the jupyter environment!
fig, ax = plt.subplots(figsize=latex_figsize( wf=0.8) ) # width of an entire latex column
ltx = Matplotlib2LaTeX(fig)
ltx.ax[0].plot(x, x**2)
ltx.ax[0].set_xlabel('x')
ltx.ax[0].set_ylabel('$x^2$')
ltx.ax[0].set_title('Trial')
ltx.save_fig('Trial.pgf')
You have your pgf file, but you can continue to work on the notebook!
fig, ax = plt.subplots(figsize=latex_figsize( wf=1) ) # width of an entire latex column
ax.plot(x, x**3)
ax.set_xlabel('x')
ax.set_ylabel('$x^3$')
ax.set_title('Trial')
plt.show()
Using the pgf output in LaTeX
Now that we have finally reproduced the plot in pgf we show how to import it in a LaTeX document. It is really straightforward, using the pgfplots
package. We make an example of the following here:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{figure}
\centering
\input{Trial.pgf}
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}
\label{fig:trial}
\end{figure}
which gives the following output. It is a little blurred, but you can look at the original .pdf
in the folder Examples_files
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 Distributions
Built Distribution
File details
Details for the file mpl2latex-0.1-py3-none-any.whl
.
File metadata
- Download URL: mpl2latex-0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2.post20210112 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375cf045787698cb17d5c0c6dca34ddb173230653670e06041ed20b1eba4033d |
|
MD5 | 4f4d5fbff2d9f394875ec703bd403c27 |
|
BLAKE2b-256 | e0e2f354942c2d747f572c7a34a95b9cecb68c73e720a7f530d5bc0167f50918 |