diff options
author | Karl Berry <karl@freefriends.org> | 2022-03-11 22:03:51 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-03-11 22:03:51 +0000 |
commit | f7047aebf5fc4b143b53cb23f9d9ea3c3eddf3be (patch) | |
tree | cebef55a7e2e238f4cb95eeac7a072191816eb60 /Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex | |
parent | 0a573a4905225d13a773434edef1a5e0bf1d3da9 (diff) |
pyluatex (11mar22)
git-svn-id: svn://tug.org/texlive/trunk@62638 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex b/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex new file mode 100644 index 00000000000..2962be862f8 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/pyluatex/example/matplotlib-pgf.tex @@ -0,0 +1,61 @@ +%% Copyright 2021-2022 Tobias Enderle +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3c or later is part of all distributions of LaTeX +%% version 2005/12/01 or later. + +\documentclass{article} + +\usepackage{pyluatex} +\usepackage{unicode-math} +\usepackage{pgf} +\usepackage{url} + +\title{PyLuaTeX Example -- Matplotlib PGF} +\author{Tobias Enderle} + +\begin{document} + +\maketitle + +In this document we demonstrate how \emph{matplotlib} plots can be generated and +included in a document. In the Python code in this document, the plot is +configured and saved to PGF\footnote{\url{https://ctan.org/pkg/pgf}} code. +The PGF code is then included in the document and creates the plot. + +To avoid intermediate files, the PGF code is saved into an in-memory file +using the Python \verb|io.StringIO| class% +\footnote{\url{https://docs.python.org/3/library/io.html#io.StringIO}}. + +\begin{center} +\begin{python} +# example based on +# https://matplotlib.org/stable/gallery/lines_bars_and_markers/simple_plot.html +import matplotlib.pyplot as plt +import numpy as np +import io + +t = np.arange(0.0, 2.0, 0.01) +s = 1 + np.sin(2 * np.pi * t) + +fig, ax = plt.subplots(figsize=(5, 3.5)) +ax.plot(t, s) + +ax.set(xlabel='time (s)', ylabel='voltage (mV)', + title='About as simple as it gets, folks') +ax.grid() + +with io.StringIO() as file: # save to "in-memory file" + fig.savefig(file, format='pgf', bbox_inches='tight', pad_inches=0.1) + print(file.getvalue()) +\end{python} +\end{center} + +For an alternative approach of creating plots with \emph{matplotlib}, +consider the example \verb|matplotlib-external.tex|. + +\end{document} |