forked from poldap/tikz-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tex
More file actions
443 lines (384 loc) · 20.6 KB
/
Copy pathmain.tex
File metadata and controls
443 lines (384 loc) · 20.6 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
\documentclass[aspectratio=169]{beamer}
% Allow for any UTF8 input (accepts é, è, ö, ä, å, etc.)
\usepackage[utf8]{inputenc}
% Hyperref for links inside the document (at cite, ref, or others)
\usepackage{hyperref}
% Drawings with TikZ, what this tutorial is all about
% TikZ ist kein Zeichenprogramm - TikZ Is Not a Drawing Program
% Part of PGF (Portable Graphics Format)
\usepackage{tikz}
% Convenient TikZ libraries
% Calc for enabling mathematical operations between points
\usetikzlibrary{calc}
% Shapes for importing shapes to easily include in your drawing
\usetikzlibrary{shapes}
% More complex and tweakable arrow shapes (generally not needed)
\usetikzlibrary{arrows}
% Package with more TikZ symbols (generally not needed)
\usepackage{tikzsymbols}
% Package with TikZ symbols for drawing circuits (generally not needed)
\usepackage{circuitikz}
% 3D TikZ (generally not needed)
\usepackage{tikz-3dplot}
% PGFplots- Package to make it easier to plot things with TikZ
\usepackage{pgfplots}
% For subplots using PGFplots
\usepgfplotslibrary{groupplots}
% If including PGFplots, it is adviced to set the compatibility to a fixed version that works. For playing, use the newest.
\pgfplotsset{ compat = newest }
% Graphicx package for images
\usepackage{graphicx}
% My recommendation for tables and complex array structures in LaTeX
\usepackage{array}
% My recommendation for reference handling with bibtex files in beamer
\usepackage[backend=bibtex,doi=false,isbn=false,url=false,style=ieee]{biblatex}
\usepackage{bibentry}
\bibliography{papers}
% Title
\title{Practical TikZ tutorial}
% Author (avoiding PDF string problems)
\author{Pol del Aguila Pla \texorpdfstring{\\}{} Ph.D. candidate at the KTH Royal Institute of Technology \texorpdfstring{\\}{} \href{mailto://poldap@kth.se}{\texttt{poldap@kth.se}}, \href{https://people.kth.se/~poldap}{\texttt{people.kth.se/\texorpdfstring{$\sim$}{}poldap}} \texorpdfstring{\\}{}
\href{https://github.com/poldap/tikz-tutorial/fork}{Fork this tutorial on GitHub: github.com/poldap/tikz-tutorial}}
% Date
\date{January 2019}
\begin{document}
\maketitle
\begin{frame}{Motivating example - $0$ words introduction}
\begin{itemize}
\item The interest of a research topic in a simple animation.
\item Creativity and clear communication.
\end{itemize}
\begin{center}
\begin{tikzpicture}
% My house
% A bed
\node at (0,0) {\Bed[4]};
% An oven
\node at (8,0) {\oven[4]};
% The walls of my home
\draw (-1.4,-0.6) rectangle (9,2.5);
% Draw a table
\draw[thick] (5,-0.5) -- (5,0.4) -- (4.8,0.4) -- (4.8,0.6) -- (6.2,0.6) -- (6.2,0.4) -- (6,0.4) -- (6,-.5) -- (5.9,-.5) -- (5.9,00.4) -- (5.1,0.4) -- (5.1,-0.5) -- cycle;
% Sleeping
\only<1>{
\node at (-0.1,0.2) [rotate=90] {\Strichmaxerl[6][60][-60]};
}
% Waking up
\only<2>{
\node at (1.5,0.2) {\Strichmaxerl[6][50][-50]};
}
% On my way
\only<3>{
\node at (2.5,0.2) {\Strichmaxerl[6][50][-50]};
\node at (-.2,-.22) [txantenna]{};
}
% There
\only<4->{
\only<4>{
\node at (3.5,0.2) {\Strichmaxerl[6][50][-50]};
}
\only<5>{
\node at (4.3,0.2) {\Strichmaxerl[6][50][-50]};
}
\only<6->{
\node at (4.3,0.2) {\Strichmaxerl[6][-45][45]};
}
\node at (8.4,.8) {\pot[1.8]};
\node at (7.35,.8) {\fryingpan[2]};
\node at (5,.78) {\Coffeecup[1]};
}
% Spies
\only<7->{
\draw (11,-0.6) -- (9.5,-0.6) -- (9.5,2.5) -- (11,2.5);
\node[red] at (10,0.2) {\Strichmaxerl[6]};
}
\end{tikzpicture}
\\
The \only<7->{{\color{red} Privacy-Aware}} Internet of Things
\end{center}
\small Introduction to an old presentation - will not be published.
\end{frame}
\begin{frame}{Simply TikZ - ex.}
\vspace{-30pt}
% An example of the outcomes one can get from simple TikZ commands. Do not try to understand straight away, go first to the next slide, "Simply TikZ - Basics"
\begin{center}
\begin{tikzpicture}[scale = 0.9,xscale = 1.2]
% Define styles - Equivalent to repeating everything inside [] every time the style is used
\tikzstyle{imagearrow} = [line width=.5mm,draw=blue!80!white,-triangle 45,postaction={draw, line width=1.5mm, shorten >=2mm, -}]
\tikzstyle{imageline} = [line width=1.5mm,draw=blue!80!white,-];
\tikzstyle{tensorarrow} = [line width=.5mm,draw=orange!80!white,-triangle 45,postaction={draw, line width=1.5mm, shorten >=2mm, -}]
\tikzstyle{tensorline} = [line width=1.5mm,draw=orange!80!white,-];
\tikzstyle{mult} = [isosceles triangle, draw, isosceles triangle apex angle=60, isosceles triangle stretches]
% Nodes in the first hidden layer
% Convolutional
% Direct operator
\node (c11) at (5,5) [draw,fill=white,shape=rectangle,inner sep = 4]{$h^{(1)}_1$};
\node (c12) at (5,4) [draw,fill=white,shape=rectangle,inner sep = 4]{$h^{(1)}_2$};
\node (c1dots) at (5,2) {\scriptsize$\begin{array}{c}\vdots\\\\(K-3)\\\vdots\end{array}$};
\node (c1K) at (5,0) [draw,fill=white,shape=rectangle,inner sep = 4]{$h^{(1)}_K$};
% Adjoint operator
\node (c11m) at (9,5) [draw,fill=white,shape=rectangle,inner sep = 4]{$-\tilde{h}^{(1)}_1$};
\node (c12m) at (9,4) [draw,fill=white,shape=rectangle,inner sep = 4]{$-\tilde{h}^{(1)}_2$};
\node (c1mdots) at (9,2) {\scriptsize$\begin{array}{c}\vdots\\\\(K-3)\\\vdots\end{array}$};
\node (c1Km) at (9,0) [draw,fill=white,shape=rectangle,inner sep = 4]{$-\tilde{h}^{(1)}_K$};
% Sums
% Image
\node (S1Ia) at (6.25,4) [draw,fill=white,shape=circle,inner sep=1pt] {\large $+$};
\node (S1Ib) at (7.3,4) [draw,fill=white,shape=circle,inner sep=1pt] {\large $+$};
% Tensor
\node (S1Ta) at (10.75,2.5) [draw,fill=white,shape=circle,inner sep=1pt] {\large $+$};
\node (S1Tb) at (14,2.5) [draw,fill=white,shape=circle,inner sep=1pt] {\large $+$};
% Multipliers by scalar
% Image
\node (mul1I) at (7.3,5.5) [mult,fill=white,inner sep = 1,rotate=-90] {\scriptsize $-1$};
% Tensor
\node (mul1T) at (14,.5) [mult,fill=white,inner sep = 1,rotate=90]{$\beta^{(1)}$};
% Non-linearity
\node (NL1) at (12.4,2.5) [draw,fill=white,shape=rectangle,inner sep = 4]{$\alpha^{(1)}\varphi_{\lambda^{(1)}}$};
% Lines and arrows in the first hidden layer
% Input to convolutional
\draw [imagearrow] (4.075,5) -- (c11);
\draw [imagearrow] (4.075,4) -- (c12);
\draw [imagearrow] (4.075,0) -- (c1K);
% Convolutional to image sums
\draw [imagearrow] (c12) -- (S1Ia);
\draw [imagearrow] (c11) -- (6.25,5) -- (S1Ia);
\draw [imagearrow] (c1K) -- (6.25,0) -- (S1Ia);
\draw [imagearrow] (S1Ia) -- (S1Ib);
% Recursive-type link from input
% Input to multiplier
\draw [imagearrow] (6.3,6.5) -- (7.3,6.5) -- (mul1I);
% Multiplier to sum
\draw [imagearrow] (mul1I) -- (S1Ib);
% Image sums to adjoint convolutional
\draw [imagearrow] (S1Ib) -- (c12m);
\draw [imagearrow] (S1Ib) -- (7.8,4) -- (7.8,5) --(c11m);
\draw [imagearrow] (S1Ib) -- (7.8,4) -- (7.8,0) --(c1Km);
% Adjoint convolutional to tensor sums
% Image lines
\draw [imageline] (c11m) -- (9.9,5);
\draw [imageline] (c12m) -- (9.9,4);
\draw [imageline] (c1Km) -- (9.9,0);
% Tensor lines
\draw [tensorline] (9.9,-.075) -- (9.9,5.075);
\draw [tensorarrow] (9.9,2.5) -- (S1Ta);
\draw [tensorarrow] (9.75,-0.75) -- (10.75,-0.75) -- (S1Ta);
% Tensor sum to non-linearity
\draw[tensorarrow] (S1Ta) -- (NL1);
% Non-linearity to tensor sum
\draw[tensorarrow] (NL1) -- (S1Tb);
% Recursive type link to previous iterate
\draw[tensorarrow] (13,-1.1) -- (14,-1.1) -- (mul1T);
\draw[tensorarrow] (mul1T) -- (S1Tb);
% Tensor sum to next layer
\draw[tensorline] (S1Tb) -- (14.8,2.5);
\draw[tensorline] (14.8,-0.075) -- (14.8,5.075);
\end{tikzpicture}
\end{center}
\vspace{-10pt}
% Citation to the paper where this figure appears
\footnotesize Part of \fullcite{AguilaPla2019}
\end{frame}
\begin{frame}{Simply TikZ - Basics}
% Basic vocabulary of using TikZ for drawing. Experiment by modifying these simple examples.
\begin{itemize}
% Listing of basic commands in the slide
\item<+-> Diagram mode keywords: \texttt{node}, \texttt{anchor}, \texttt{draw}, \texttt{rotate}, \texttt{opacity}, \texttt{--}, \texttt{-- ++}, \texttt{-}, \texttt{->}, \texttt{<-}, \texttt{thick}, \texttt{very thin}, \texttt{dashed}, \texttt{dotted}, \texttt{dashdotted}, \texttt{midway}, \texttt{below}, \texttt{fill}
% Listing of code for the first example figure
\item<+-> \texttt{\textbackslash node[draw] (a) at (-1,0) \{[A]\}; \textbackslash node (b) at (1,0) \{[B]\}; \textbackslash draw[<->] (a) -- (b);}
% First example. MODIFY HERE and EXPERIMENT.
\begin{center}
\begin{tikzpicture}
\node[draw] (a) at (-1,0) {[A]}; \node (b) at (1,0) {[B]}; \draw[<->] (a) -- (b);
\end{tikzpicture}
\end{center}
% Listing of code for the second example figure
\item<+-> \texttt{\textbackslash node[draw,shape=circle,rotate=90] at (-1,0) \{\$1\$\}; \textbackslash node[draw=blue,very thick,shape=circle,fill=red,opacity=0.5,anchor=south] (b) at (1,0) \{\$2\$\}; \textbackslash draw[-latex,thick,dashdotted] (a.south) --++ (0,-0.4) --++ (1,0) -- (b.west) node[midway,above,rotate=60] \{middle\};}
% Second example. MODIFY HERE and EXPERIMENT.
\begin{center}
\begin{tikzpicture}
\node[draw,shape=circle,rotate=90] at (-1,0) {$1$}; \node[draw=blue,very thick,shape=circle,fill=red,opacity=0.5,anchor=south] (b) at (1,0) {$2$}; \draw[-latex,thick,dashdotted] (a.south) --++ (0,-0.4) --++ (1,0) -- (b.west) node[midway,above,rotate=60] {middle};
\end{tikzpicture}
\end{center}
\end{itemize}
% Now, try to understand how the diagram in the previous slide, "Simply TikZ - ex." and experiment with it. What would you have done differently?
\end{frame}
\begin{frame}{Simply TikZ + 3D + loops - ex.}
\vspace{-15pt}
\begin{center}
% Thanks to the array package, it is easy to create cells in a tabular with paragraph structure (text folding at the end of line, etc.). You need to specify the width, however.
\begin{tabular}{m{.5\textwidth}m{.4\textwidth}}
% The practical way of handling TikZ figures, as separate .tex files you input
\input{figs/discretization_grid}
% Explore the use of variables (\def), commands (\newcommand), for loops (\foreach) and color definitions (gray!40 = gray!40!white) in the published figure in figs/discretization_grid. MODIFY and EXPERIMENT. The simplicity of 3D comes from the great package tikz-3dplot.
&
% Listing of new concepts with respect to the previous
\begin{itemize}
\item More concepts and keywords: \texttt{\textbackslash def}, \texttt{\textbackslash foreach}, \texttt{\textbackslash pgfmathsetmacro}, \texttt{gray!40!blue}, \texttt{\textbackslash newcommand}
\end{itemize}
% Citation to paper where this figure appears
{\footnotesize
Part of \fullcite{AguilaPla2017}
}
\end{tabular}
\end{center}
\end{frame}
\begin{frame}{Simply TikZ for plotting}
\vspace{-10pt}
\begin{center}
% Explore the use of 'plot file', 'plot function', and the keywords 'domain' and 'samples'. MODIFY and EXPERIMENT.
% Set the scales of each axis and start figure
\begin{tikzpicture}[xscale=1,yscale=15]
% Draw axis
\draw [->] (0,0) -- (0,0.3) node [anchor=south] {$f_x(x)$};
\draw [->] (-5,0) -- (5.1,0) node [anchor=west] {$x$};
% Draw labels
% X axis
\foreach \x in {-5, -4, ..., 5}
\draw (\x,0) node[anchor=north] {\scriptsize $\x$};
% Y axis (with arbitrary labels, double for)
\foreach \y/\ytext in {0.125/\tfrac{1}{8},0.25/\tfrac{1}{4}}
\draw (0,\y) node[anchor=west] {\scriptsize $\ytext$};
% Plot for the actual distribution of some data
% EXPERIMENT with changing the function expression
% what happens with less samples?
\draw[smooth,domain=-5:5,samples=400] plot
function{ (1/sqrt(2*pi))*( % Gaussian normalization factor (with std = 1)
0.5*sqrt(2)*exp((-(x+2)**2))+ % Gaussian with weight (prob) 0.25 and stdeviation 1/sqrt(2) around -2
0.5*exp((-(x-1)**2)/2))}; % Gaussain with weight (prob) 0.75 and stdeviation 1 around 1
% Plot sampled data
% The file data.txt is only two columns of numbers separated by spaces, check it out.
\draw plot[only marks, mark=*, mark size=0.07pt, mark options={color=red!80}] file{figs/data.txt};
% Plot histogram estimation
% Why set the fill opacity at 0.5? Does it help for this figure?
\draw[fill=orange, fill opacity=0.5] plot[ybar] file{figs/hist.txt};
\draw[orange] node at (4,0.27) {\scriptsize Histogram};
% Plot parametric model fittings
% What does smooth do? let's try to change the colors, thicknesses, opacities, etc? What if we want markers to indicate the data points?
\draw[color=blue] plot[smooth] file{figs/gen_pareto.txt};
\draw[color=red] plot[smooth] file{figs/gen_extr_value.txt};
\draw[color=green] plot [smooth] file{figs/normal.txt};
% Names of parametric model fittings (note the equivalence between \node and \draw node
\node at (4,0.30) {\scriptsize True distribution};
\draw[color=blue] node at (4,0.24) {\scriptsize Generalized Pareto};
\draw[color=red] node at (4,0.21) {\scriptsize Generalized Extreme Value};
\draw[color=green] node at (4,0.18) {\scriptsize Normal};
\end{tikzpicture}
\end{center}
\vspace{-20pt}
\begin{itemize}
\item More concepts and keywords: \texttt{plot file}, \texttt{smooth}, \texttt{ybar}, \texttt{plot function}, \texttt{domain}, \texttt{samples}
\end{itemize}
\small Part of an old presentation - will not be published.
\end{frame}
\begin{frame}{Simply TikZ scripted plotting - ex.}
\vspace{-15pt}
\begin{center}
% See file, mainly generated by a MATLAB script that writes out TikZ lines after computing the statistics of the results. Extremely easy to script using fprintf onto an open file.
\input{figs/vs_NC_NL3+4_new_with_human}
\end{center}
\vspace{-15pt}
\begin{itemize}
\item Easily scripted
\end{itemize}
{\footnotesize
Part of \fullcite{AguilaPla2017a}
}
\end{frame}
\begin{frame}{PGFplots - Easier plotting}
% Column environment from beamer. Good for this kind of alignment.
\begin{columns}[T]
% Figure column, EXPERIMENT here
\begin{column}{.48\textwidth}
% The simplicity of PGFplots is appealing. Try to configure this simple plot to your liking. Try adding markers. Can you set how many samples of the function are used for the drawing? Change the function, how does it behave compared to "Simply TikZ for plotting"? Can you set the minimum and maximum values for each axis?
\begin{tikzpicture}
\begin{axis}[
title = {$f(x) = x^2$},
grid = major,
xlabel = {$x$},
ylabel = {$f(x)$},
width=\textwidth
]
\addplot[domain = -1:1] {x^2};
\end{axis}
\end{tikzpicture}
\end{column}\hfill
% Listing of the code for the example figure
\begin{column}{.48\textwidth}
\vspace{40pt}
\texttt{\textbackslash begin\{axis\}[
title = \{\$f(x) = x\^{}2\$\},grid = major,xlabel = \{\$x\$\},ylabel = \{\$f(x)\$\},]
\textbackslash addplot[domain = -1:1] \{x\^{}2\}; \textbackslash end\{axis\}}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{PGFplots - Easier 3D plotting}
\begin{columns}[T]
% Figure column, EXPERIMENT here. Can you change the colours? Can you include a colorbar? Change the function and the number of samples.
\begin{column}{.45\textwidth}
\begin{tikzpicture}
\begin{axis}[title = {$f(x,y) = x^2 + y^2$},grid = major,xlabel = {$x$},ylabel = {$y$},zlabel={$f(x,y)$},width=\textwidth]
\addplot3[surf,domain = -1:1,samples=20] {x^2+y^2};
\end{axis}
\end{tikzpicture}
\end{column}\hfill
% Listing of the code for the example figure
\begin{column}{.48\textwidth}
\vspace{30pt}
\texttt{\textbackslash begin\{axis\}[ title = \{ \$f(x,y) = x\^{}2 + y\^{}2\$\}, grid = major, xlabel = \{\$x\$\}, ylabel = \{\$y\$\},zlabel=\{\$f(x,y)\$\},]
\textbackslash addplot3[surf,domain = -1:1,samples=20] \{x\^{}2+y\^{}2\};
\textbackslash end\{axis\}}
\end{column}
\end{columns}
\end{frame}
\begin{frame}{PGFplots from Python (matplotlib2tikz)}
% If you are familiar with matplotlib, explore the screen capture of a Jupyter notebook on the slide
\only<1>{
\begin{center}
\includegraphics[keepaspectratio=true,width=.95\textwidth]{figs/creating_example.png}
\end{center}
}
% Simply importing the file saved by the Jupyter notebook, we obtain this very good starting point.
\only<2>{
\begin{columns}
% Input figure
\begin{column}{.58\textwidth}
\input{figs/example}
\end{column}\hfill
% Listing of input figure
\begin{column}{.4\textwidth}
\texttt{\textbackslash input\{figs/example\} }
\end{column}
\end{columns}
}
% Small modifications provide an amazing-looking figure with scalable graphics, font integration, re-usability, and most of the other advantages of TikZ in minutes
\only<3>{
% EXPLORE the differences between 'figs/example' and 'figs/example_improved' and EXPERIMENT
\input{figs/example_improved}
% Same message in the slide
\begin{itemize}
\item less than $5$ minutes of work away (compare \texttt{figs/example.tex} with \texttt{figs/example\_improved.tex}).
\end{itemize}
}
\end{frame}
\begin{frame}{PGFplots from Python (matplotlib2tikz) - ex.}
\vspace{-10pt}
\begin{center}
\input{figs/convergence_networks}
\end{center}
\vspace{-10pt}
Explore \href{https://github.com/poldap/SpotNet}{github.com/poldap/SpotNet} to see the generation of these figures in Python.
\vspace{5pt}
{\footnotesize Part of \fullcite{AguilaPla2019}}
\end{frame}
\begin{frame}{Practical TikZ Tutorial - Remarks}
\begin{itemize}
\item Use the same styles (fonts, font sizes, math symbols, etc.) across your papers, i.e., in your figures, in your text, etc.
\item Work only with scalable graphics
\item Put no limits on the drawing possibilities, promote creativity and clear communication
\item Re-use drawings and figures, get your time back
\item Use TikZ :-D
\end{itemize}
A word of warning: local compilation will require \texttt{pdflatex -shell-escape} or \texttt{pdflatex --shell-escape} (depending on your \LaTeX distribution) for many of the examples. Compliation time will benefit from the use of \texttt{\textbackslash usetikzlibrary\{external\}} \texttt{\textbackslash tikzexternalize} in the preamble of your document.
\end{frame}
\end{document}