-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.tex
116 lines (95 loc) · 4.29 KB
/
example.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
\documentclass[a4paper,12pt]{article}
\date{\today}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{authblk}
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{pgf}
% Biblatex support for references
\usepackage[style=numeric]{biblatex}
\addbibresource{references.bib}
%\addbibresource{references.bib}
%Get rid of these nasty lines around links
\hypersetup{pdfborder=0 0 0}
\author{Robert Sawko}
\affil{Department of Engineering Computing, Cranfield University}
\title{Python and PGF}
%Setting a nicer(?) TrueType font (which needs xetex)
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text}
\setmainfont{Liberation Serif}
\begin{document}
\maketitle
\begin{abstract}
This document presents example usage of \texttt{matplotlib} together with
\LaTeX. We will use the PGF in order to create low-level drawing macros which
will be compiled by \texttt{xelatex}. We will also cover a generation of
figures and legend separately which in some situations is beneficial.
\end{abstract}
\section{Introduction}
I prepared these files in a response to one of the questions about
\texttt{matplotlib} capability to generate graphs in \LaTeX\ format. The main
advantage of this is better integration of the document with the graphs as the
fonts, font sizes etc.\ will be obtained during the compilation of the document
rather than each figure. This may eliminate invisible labels, ticks and other
artifacts haunting people writing large documents.
The integration is achieved via PGF backend. To find out more about backends
read \cite{backend}. PGF backend is described \cite{pgf}. PGF stands for
Portable Network Graphics - more can be found in \cite{pgfwiki}.
Admittedly, \texttt{matplotlib} is a bit more involved than \texttt{gnuplot}.
You often need to invoke more commands which are not intuitively clear. On the
other hand it is more flexible and can be used in any python code with potential
loops over directory structure. This cannot be achieved with bare
\texttt{gnuplot} without some scripting which quickly gets more involved than a
readable Python code. Also, \texttt{matplotlib} seems to offer more
functionalities. Personally, I use \texttt{gnuplot} for interactive plotting as
I can obtain plots straight from the files. I use \texttt{matplotlib} for larger
final documents.
Note that I tried to keep the setup simple without a use of fancy build systems
or self configuration tools. Graph generation and document compilation could be
run with a single command. The use would become very simple but the
configuration, the scripts etc would have become more complex. For now the
purpose is to demonstrate PGF and \LaTeX integration and show some good
practices. In the future I may add branches for people who would like to see how
to run this with \texttt{make} or \texttt{cmake}.
\section{Example figures}
Several examples are presented here. On figure~\ref{fig:latex} we are simply
looking at the capability of plotting via PGF\@. Figure~\ref{fig:several} we are
mainly looking at using legend as a separate graph that is only tied to the actual
plots at the level of the document. This approach is beneficial if you are
plotting many figures of the same type and the legend would have been repeated
on each graph. Also, having a legend outside of the plot makes the plot clearer
as there is nothing to obscure the results.
\begin{figure}[t]
\centering
%note that we're using \input!
\input{graphics/bessel.pgf}
\\
\caption{I am printing word "abscissa" just to prove that the fonts are
matched. We're also admiring a \LaTeX\ equations on the graph.}
\label{fig:latex}
\end{figure}
\begin{figure}[p]
\begin{center}
\input{graphics/ReG0150ReL0150.pgf}
\input{graphics/ReG1500ReL0150.pgf}
\\
\vspace{5mm}
\input{graphics/ReG0150ReL1500.pgf}
\input{graphics/ReG1500ReL1500.pgf}
\\
\input{graphics/legend.pgf}
\end{center}
\caption{Several figures and a legend. Note the convenience of having the
legend in the actual document. It doesn't have to be assigned to any subplot.}
\label{fig:several}
\end{figure}
\section{Future work}
\begin{enumerate}
\item Include an automated build system like Make or CMake.
\item Include different branches for advanced and novice users.
\item Check if is compatible Windows!
\end{enumerate}
\printbibliography
\end{document}