Elmag Seminar Tikz Ver1.2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

Graphics in LATEX

An introduction into TikZ and pgfplots package

Michal Mašek
michal.masek@fel.cvut.cz

Department of Electromagnetic Field,


Czech Technical University in Prague

Departmental seminars
May 7 and 14, 2019

Michal Mašek Graphics in LATEX 1 / 30


Outline

Outline

1. Introduction
2. Figures with TikZ
3. Graphs in LATEX- pgfplots
4. Drawing in Graphs

Why to do graphics in LATEX?


To avoid this1 !

1 M. Masek, “Coaxial Cable,” Bachelor Thesis, Czech Technical University in Prague, Czech Republic, 2013.
Michal Mašek Graphics in LATEX 2 / 30
Introduction

Introduction

Use Google!
Every problem you have, someone else already solved...

From many results,


try to find a simple, understandable, and general solution.

Michal Mašek Graphics in LATEX 3 / 30


Introduction

How to prepare figures n LATEX

Draw figures with tikz package2 . Plot graphs with pgfplot package2 .
270
Cz2

characteristic angle δ n (deg)


240
ψ2 A1
ψ1 210 A2

ψ3 σvxz 180
E
T1
T2
150

ψ4 120
ψ5
90
σvyz 1 3 5 7 9
electrical size ka
11 13 15

I Combine both together!

2 M. Masek, M. Capek, L. Jelinek, and K. Schab, “Modal Tracking Based on Group Theory,” submited to

IEEE Trans. Antennas Propag., 2018.


Michal Mašek Graphics in LATEX 4 / 30
Figures with TikZ

Outline

1. Introduction
w
2. Figures with TikZ
3. Graphs in LATEX- pgfplots
4. Drawing in Graphs
l

h
PIFA structure3 .
3 M. Masek, J. Rymus, P. Hazdra and M. Capek, “Implementation of the Theory of Characteristic Modes

into Antenna Modeling Tools and Their Benchmarking,” 8th Microwave and Radar Week, Poznan, Poland,
2018.
Michal Mašek Graphics in LATEX 5 / 30
Figures with TikZ

TikZ – How to start

I TikZ: the LATEXpackage for vector graphic


developed by Till Tantau.
I Tikz + PGF manual
I Minimal introduction to TikZ

Michal Mašek Graphics in LATEX 6 / 30


Figures with TikZ

TikZ – How to start


\usepackage{tikz}
I TikZ: the LAT
EXpackage for vector graphic
developed by Till Tantau.
I Tikz + PGF manual
I Minimal introduction to TikZ

I Load the package.

Michal Mašek Graphics in LATEX 6 / 30


Figures with TikZ

TikZ – How to start


\usepackage{tikz}
I TikZ: the LAT
EXpackage for vector graphic
developed by Till Tantau. \begin{tikzpicture}
I Tikz + PGF manual Your code
I Minimal introduction to TikZ
\end{tikzpicture}

I Load the package.


I TikZ environment: tikzpicture.

Michal Mašek Graphics in LATEX 6 / 30


Figures with TikZ

TikZ – How to start


\usepackage{tikz}
I TikZ: the LAT
EXpackage for vector graphic
developed by Till Tantau. \begin{figure}
I Tikz + PGF manual \begin{tikzpicture}
I Minimal introduction to TikZ
Your code
\end{tikzpicture}
I Load the package. \caption{Caption of the figure...}
I TikZ environment: tikzpicture. \begin{figure}
I In the document, can be included into
figure environment.

Michal Mašek Graphics in LATEX 6 / 30


Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw (0,0) -- (1,2);
\end{tikzpicture}

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw (0,0) -- (1,2);
I Every command has to be ended \end{tikzpicture}
with semicolon!

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw (0,0) -- (1,2);
I Every command has to be ended \end{tikzpicture}
with semicolon!
I Default units are centimeters.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw (0,0) -- (1,2) -- (2,1.7) -- (1,0);
I Every command has to be ended \end{tikzpicture}
with semicolon!
I Default units are centimeters.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw (0,0) -- (1,2) -- (2,1.7) -- (1,0);
I Every command has to be ended \draw (2,0) -- (-0.5,1.5);
with semicolon! \end{tikzpicture}
I Default units are centimeters.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw (0,0) -- ++ (1,0) -- ++ (1,1);
I Every command has to be ended \end{tikzpicture}
with semicolon!
I Default units are centimeters.
I Relative increasing: ++.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw[thick, rounded corners] (0,0) -- (1,2)
I Every command has to be ended -- (2,1.7) -- (1,0);
with semicolon! \draw[->, red, dashed] (2,0) -- (-0.5,1.5);
\draw[ultra thick, green] (0,0) -- ++ (1,0) --
I Default units are centimeters. ++ (1,1);
I Relative increasing: ++. \end{tikzpicture}
I Specifications are in [].

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw [blue] (0,0) rectangle (2,1.5);
I Every command has to be ended \draw [purple, dashed] (-0.2,1.2) circle
with semicolon! [radius=0.7];
\draw [gray, ultra thick] (1.5,1) arc
I Default units are centimeters. [radius=1, start angle=0, end angle= 90];
I Relative increasing: ++. \end{tikzpicture}
I Specifications are in [].
I Other shapes: rectangle, circle,
arc, plot.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw [stealth-stealth] (0,2) -- (0,0) --
I Every command has to be ended (2,0);
with semicolon! \draw[green, ultra thick, domain=-1.4:1.4]
plot (\x+1, 0.01+\x*\x);
I Default units are centimeters. \end{tikzpicture}
I Relative increasing: ++.
I Specifications are in [].
I Other shapes: rectangle, circle,
arc, plot.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic Commands I.


\begin{tikzpicture}
I Basic command for drawing: \draw. \draw[red, thick, fill = red!30] (-1,0)
I Every command has to be ended rectangle (2.5,2.2);
with semicolon! \draw [blue, ultra thick] (0.5,0.5) arc
[radius=1, start angle=0, end angle= 90];
I Default units are centimeters. \draw [black, ultra thick, fill = black!30]
I Relative increasing: ++. (1.5,0.5) arc [radius=1, start angle=0, end
I Specifications are in []. angle= 90];
\end{tikzpicture}
I Other shapes: rectangle, circle,
arc, plot.
I fill.

The solution.
Michal Mašek Graphics in LATEX 7 / 30
Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \draw [thick, <->] (0,2) -- (0,0) -- (2,0);
\node at (1,1) {text};
\end{tikzpicture}

text

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \draw [thick, <->] (0,2) -- (0,0) -- (2,0);
\draw[fill] (1,1) circle [radius=0.025];
I Position of text at node. \node [below, red] at (1,1) {below};
\node [above, blue] at (1,1) {above};
\node [left, green] at (1,1) {left};
\node [right, purple] at (1,1) {right};
\end{tikzpicture}

above
left right
below

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \draw [thick, <->] (0,2) -- (0,0) -- (2,0);
\draw[fill] (1,1) circle [radius=0.025];
I Position of text at node. \node [below right, red] at (1,1) {below right};
\node [above left, blue] at (1,1) {above left};
\node [below left, green] at (1,1) {below left};
\node [above right, purple] at (1,1) {above
right};
\end{tikzpicture}

above left above right


below left below right

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \node [draw = red, fill = blue!20, circle] at
(-0.2, 1.5) {circ};
I Position of text at node. \node [draw = red, fill = blue!20, circle] at
I \draw + \node. (1.5,1) {circ XXX};
\end{tikzpicture}

circ
circ XXX

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \tikzstyle{myCircle}=[draw = red, fill = blue!20,
circle]
I Position of text at node. \node [myCircle] at (-0.2,1.5) {circ};
I \draw + \node. \node [myCircle] at (1.5,1) {circ XXX};
I Styles: \tikzstyle. \end{tikzpicture}

circ
circ XXX

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \tikzstyle{myCircle}=[draw = red, fill = blue!20,
circle]
I Position of text at node. \coordinate (center1) at (-0.2,1.5);
I \draw + \node. \coordinate (center2) at (1.5,1);
\node [myCircle] at (center1) {circ};
I Styles: \tikzstyle.
\node [myCircle] at (center2) {circ XXX};
I Coordinations: \coordinate. \end{tikzpicture}

circ
circ XXX

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \tikzstyle{myCircle}=[draw = red, fill = blue!20,
circle]
I Position of text at node. \coordinate (center1) at (-0.2,1.5);
I \draw + \node. \coordinate (center2) at (1.5,1);
\node (circ1) [myCircle] at (center1) {circ};
I Styles: \tikzstyle.
\node (circ2) [myCircle] at (center2) {circ XXX};
I Coordinations: \coordinate. \end{tikzpicture}
I Naming nodes.

circ
circ XXX

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \node (sq) [draw = black, fill = black!20,
minimum height = 2cm, minimum width = 2cm] at (1,1)
I Position of text at node. {AAA};
I \draw + \node. \draw[fill = red] (sq.north) circle [radius=0.1];
\draw[fill = blue] (sq.west) circle [radius=0.1];
I Styles: \tikzstyle.
\draw[fill = green] (sq.south) circle
I Coordinations: \coordinate. [radius=0.1];
I Naming nodes. \draw[fill = purple] (sq.east) circle
[radius=0.1];
I Anchors of nodes. \draw[fill = cyan] (sq.north west) circle
[radius=0.1];
\draw[fill = yellow] (sq.north east) circle
[radius=0.1];
AAA \draw[fill = orange] (sq.south west) circle
[radius=0.1];
\draw[fill = magenta] (sq.south east) circle
[radius=0.1];
The solution. \end{tikzpicture}

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic commands II.


\begin{tikzpicture}
I Text: \node. \tikzstyle{myCircle}=[draw = red, fill = blue!20,
circle]
I Position of text at node. \coordinate (center1) at (-0.2,1.5);
I \draw + \node. \coordinate (center2) at (1.5,1);
\node (circ1) [myCircle] at (center1) {circ};
I Styles: \tikzstyle.
\node (circ2) [myCircle] at (center2) {circ XXX};
I Coordinations: \coordinate. \draw[->, thick] (circ1.south) -- (circ2.south);
I Naming nodes. \end{tikzpicture}
I Anchors of nodes.

circ
circ XXX

The solution.

Michal Mašek Graphics in LATEX 8 / 30


Figures with TikZ

TikZ – Basic Commands III.


\begin{tikzpicture}
I The calculation of coords: \coordinate (a) at (-0.5, 0.5);
\coordinate (b) at (2.5, 0.5);
\usetikzlibrary{calc}.
\coordinate (c) at ($(a) !0.5! (b)$);
I Notation: \coordinate (d) at ($(a) !1/3! (c)$);
!0.5! at 1/2 between given \coordinate (e) at ($(a) + (0, 1)$);
points, \coordinate (f) at ($(b) + (-0.5, 0.5)$);
!1/3! at 1/3 between given \coordinate (g) at ($(b) + 2*(-0.5, 0.5)$);
points, \coordinate (h) at ($(g) + -1*(0.5, 0.5)$);
+ adding of two vectors. \tikzstyle{myPoint} = [draw = black, fill = black];
subtraction also with +, see (h). \tikzstyle{myCirc} = [radius = 0.05];
\draw[<->, gray] (0, 2) -- (0,0) -- (2,0);
\draw[myPoint] (a) circle [myCirc] node[above] {A};
E G \draw[myPoint] (b) circle [myCirc] node[above] {B};
\draw[myPoint] (c) circle [myCirc] node[above] {C};
H F \draw[myPoint] (d) circle [myCirc] node[above] {D};
A D C B \draw[myPoint] (e) circle [myCirc] node[above] {E};
\draw[myPoint] (f) circle [myCirc] node[above] {F};
\draw[myPoint] (g) circle [myCirc] node[above] {G};
The solution. \draw[myPoint] (h) circle [myCirc] node[above] {H};
\end{tikzpicture}
Michal Mašek Graphics in LATEX 9 / 30
Figures with TikZ

TikZ – Basic Commands IV.


% line
I Text (not only) above line: \draw (0,0) -- (5,0);
% text above ending point:
\draw and \node combination.
\draw[red] (0,1) -- (5,1) node[above] {a};
I Both commands can be % text above line
combined, position of node \draw[green] (0,2) -- node[above] {a} (5,2);
command affect position of text. % text above starting point:
\draw[blue] (0,3) node[above] {a} -- (5,3);
a % text at specified position:
\draw[cyan] (0,4) -- node[above, pos=0.2] {a} (5,4);
a
a
a

The solution.

Michal Mašek Graphics in LATEX 10 / 30


Figures with TikZ

TikZ – Complex example I.

I Generator – modulator – transmitting antenna – free space – receiving antenna –


demodulator – receiver.

Free space

GEN MOD DEMOD Receiver

The block diagram of signal transfer.

Michal Mašek Graphics in LATEX 11 / 30


Figures with TikZ

TikZ – Complex example I. – Source Code I.


% LaTeX definitions of dimensions % Transmitting antenna
\newlength{\blockHeight} % height of block \coordinate (ant1A) at ($(mod.east) + (\blockSeparator,
\setlength{\blockHeight}{1.2cm} 0) + -0.5*(\blockWidth, 0)$);
\newlength{\blockWidth} % width of block \coordinate (ant1B) at ($(ant1A) + (0,
\setlength{\blockWidth}{1.5cm} 3/2*\blockHeight)$);
\newlength{\blockSeparator} % space between blocks \draw[antenna] (ant1A) -- (ant1B);
\setlength{\blockSeparator}{1cm} \draw[antenna] ($(ant1B)+(-\antennaX, 0)$) --
\newlength{\antennaX} % antenna fork - X ($(ant1B)+(0, -\antennaY)$) -- ($(ant1B)+(\antennaX,
\setlength{\antennaX}{0.2cm} 0)$);
\newlength{\antennaY} % antenna fork - Y
\setlength{\antennaY}{0.4cm} % Receiving antenna
\begin{tikzpicture} \coordinate (ant2A) at ($(ant1A) + (3*\blockSeparator,
% My stylles - block, antenna and arrow 0)$);
\tikzstyle{block} = [rectangle, draw = black, minimum \coordinate (ant2B) at ($(ant2A) + (0,
height = \blockHeight, minimum width = \blockWidth, 3/2*\blockHeight)$);
inner sep = 0pt]; \draw[antenna] (ant2A) -- (ant2B);
\tikzstyle{antenna} = [draw = black, thick]; \draw[antenna] ($(ant2B)+(-\antennaX, 0)$) --
\tikzstyle{arrow} = [->, thick]; ($(ant2B)+(0, -\antennaY)$) -- ($(ant2B)+(\antennaX,
0)$);
% Generator
\coordinate (genCoord) at (0,0); % demodulator
\node[block, circle, minimum width = \blockHeight] \coordinate (demodCenter) at ($(ant2A) +
(gen) at (genCoord) {GEN}; (\blockSeparator, 0)$);
\node[block] (demod) at (demodCenter) {DEMOD};
% Modulator
\coordinate (modCenter) at ($(gen.east) +
(\blockSeparator, 0) + 0.5*(\blockWidth, 0)$);
\node[block] (mod) at (modCenter) {MOD};
Michal Mašek Graphics in LATEX 12 / 30
Figures with TikZ

TikZ – Complex example I. – Source Code II.


% Receiver
\coordinate (recCenter) at ($(demod.east) + (\blockSeparator, 0) + 0.5*(\blockWidth, 0)$);
\node[block] (rec) at (recCenter) {P\v{r}ij\’{i}ma\v{c}};
% Propojen blok
\draw[arrow] (gen.east) -- (mod.west);
\draw[arrow, -] (mod.east) -- (ant1A);
\draw[arrow] (ant2A) -- (demod.west);
\draw[arrow] (demod.east) -- (rec.west);

% Free space
\coordinate (air1) at ($(ant1B) + (2* \antennaX, 0)$);
\coordinate (air2) at ($(ant2B) + (-2* \antennaX, 0)$);
\draw[arrow, cyan, dashed] (air1) -- (air2);
\node[cyan, below] at ($(air1) !0.5! (air2)$) {Free space};
\end{tikzpicture}

Michal Mašek Graphics in LATEX 13 / 30


Figures with TikZ

TikZ – Complex example II.

r ra

r ab
a b

r rr0
r br0

r0
Vectors adding.

Michal Mašek Graphics in LATEX 14 / 30


Figures with TikZ

TikZ – Complex example II. – Source Code


\documentclass[12pt]{standalone} % arrows
\usepackage{tikz} \draw[myArrow] (r1) -- node [right, midway]
\usetikzlibrary{calc} {$\V{r} {br’}$} (b);
\usepackage{amsmath} \draw[myArrow] (b) -- node [above, pos = 0.3]
\usepackage{amsfonts} {$\V{r} {ab}$} (a);
\draw[myArrow] (a) -- node [left, midway] {$\V{r} {ra}$}
\newcommand{\V}[1]{\boldsymbol{#1}} % vector (r);
\newcommand{\circleRad}{1.5pt} \draw[myArrow, thick, style = densely dashed, red] (r1)
\newcommand{\fWidth}{7cm} -- node[below left, pos = 0.35] {$\V{r} {rr’}$} (r);
\newcommand{\fHeight}{5cm}
% points
\tikzstyle{myPoint} = [radius = \circleRad, \draw[myPoint] (r1) circle node [right] {$\V{r}’$};
black, fill = black] \draw[myPoint] (b) circle node [right] {$\V{b}$};
\tikzstyle{myArrow} = [->, >=stealth, shorten >= \draw[myPoint] (a) circle node [left] {$\V{a}$};
\circleRad] \draw[myPoint] (r) circle node [left] {$\V{r}$};
\end{tikzpicture}
\begin{document} \end{document}
\begin{tikzpicture}
\coordinate (r1) at (\fWidth, 0cm);
\coordinate (b) at (\fWidth, 0.5*\fHeight);
\coordinate (a) at (0, 0.5*\fHeight);
\coordinate (r) at (0, \fHeight);

Michal Mašek Graphics in LATEX 15 / 30


Figures with TikZ

GeoGebra: Online Application

I Browser application to draw


geometry.
I GeoGebra

I Can be downloaded as TikZ code.


Menu - Save as - PGF/TikZ.
I It is automatic code.
I It requires user’s updates and
improvements.

GeoGebra application.

Michal Mašek Graphics in LATEX 16 / 30


Figures with TikZ

circuitikz
\usepackage[europeanresistors]{circuitikz}
I Documentation: I circuitikz % ...
I Predefined styles for electrical and
electronic networks.

Michal Mašek Graphics in LATEX 17 / 30


Figures with TikZ

circuitikz
\usepackage[europeanresistors]{circuitikz}
I Documentation: I circuitikz % ...
\begin{circuitikz}
I Predefined styles for electrical and \end{circuitikz}
electronic networks.
I circuitikz environment.

Michal Mašek Graphics in LATEX 17 / 30


Figures with TikZ

circuitikz
\usepackage[europeanresistors]{circuitikz}
I Documentation: I circuitikz % ...
\begin{circuitikz}
I Predefined styles for electrical and \draw (0, 0) to[R=$R 0$] (2, 0);
electronic networks. \end{circuitikz}
I circuitikz environment.
I \to command.

R0

The solution.

Michal Mašek Graphics in LATEX 17 / 30


Figures with TikZ

circuitikz
\usepackage[europeanresistors]{circuitikz}
I Documentation: I circuitikz % ...
\begin{circuitikz}
I Predefined styles for electrical and \draw (0, 0) to[short, o-] (0, 0);
electronic networks. \draw (0, 0) to[R=$R 0$] (2, 0);
I circuitikz environment. \draw (2, 0) to[short,-*] ++(0,0);
I \to command. \end{circuitikz}

R0

The solution.

Michal Mašek Graphics in LATEX 17 / 30


Figures with TikZ

circuitikz
\usepackage[europeanresistors]{circuitikz}
I Documentation: I circuitikz % ...
\begin{circuitikz}
I Predefined styles for electrical and \draw (0, 0) to[short, o-] (0, 0);
electronic networks. \draw (0, 0) to[R=$R 0$] (2, 0);
I circuitikz environment. \draw (2, 0) to[short,-*] ++(0,0);
I \to command. \draw (2, 0) to[R=$R 1$] ++(2, 0);
\draw (4, 0) to[short,-*] ++(0,0);
\end{circuitikz}

R0 R1

The solution.

Michal Mašek Graphics in LATEX 17 / 30


Figures with TikZ

circuitikz
\usepackage[europeanresistors]{circuitikz}
I Documentation: I circuitikz % ...
\begin{circuitikz}
I Predefined styles for electrical and \draw (0, 0) to[short, o-] (0, 0);
electronic networks. \draw (0, 0) to[R=$R 0$] (2, 0);
I circuitikz environment. \draw (2, 0) to[short,-*] ++(0,0);
I \to command. \draw (2, 0) to[R=$R 1$] ++(2, 0);
\draw (4, 0) to[short,-*] ++(0,0);
C \draw (2, 0) --++ (0, 1.2) to[C=$C$]
++(2, 0) --++ (0, -1.2);
\draw (2, 0) --++ (0, -1.2) to[L=$L$]
++(2, 0) --++ (0, 1.2);
R0 R1 \draw (4, 0) to[short,-o] ++(0.5,0);
\end{circuitikz}
L

The solution.

Michal Mašek Graphics in LATEX 17 / 30


Figures with TikZ

circuitikz – Block Diagram

LS tunning of antenna – block diagram.

Michal Mašek Graphics in LATEX 18 / 30


Figures with TikZ

circuitikz – Block Diagram – Source Code


\documentclass[tikz]{standalone} % second LC block
\usepackage[]{circuitikz} \node[myBlock] (recB) at (5,-1.6) {
\begin{document} \begin{circuitikz}
\draw (0,0) to[L] (0,2);
\tikzstyle{myBlock} = [draw, black, line width=0.5, \draw (1,0) to[C] (1,2);
scale=0.85, fill=black!5!white, minimum width=2.4cm, minimum \end{circuitikz}
height=2.8cm] };
\begin{tikzpicture}
% antenna
% surrounding rectangle \node[myBlock] (recC) at (8,-1.6) {
\draw[black, fill=white, line width=0.25pt] (0.2, 1.32) \begin{circuitikz}
rectangle (9.32,-3.5); \node[antenna]{};
\end{circuitikz}
% connection lines };
\draw (0.5,0) to[short, o-] ++(4.5,0) to[short, *-] ++(3,0)
to (8,-3.2); \end{tikzpicture}
\draw (0.5,-3.2) to[short, o-] ++(4.5,0) to[short, *-] \end{document}
++(3,0) to (8,0);
\draw (5,0) to (5,-3.2);

% first LC block
\node[myBlock, rotate=270] (recA) at (2.25,0) {
\begin{circuitikz}
\draw (0,0) to[L] (0,2);
\draw (1,0) to[C] (1,2);
\end{circuitikz}
};

Michal Mašek Graphics in LATEX 19 / 30


Graphs in LATEX- pgfplots

Outline

1. Introduction
20
2. Figures with TikZ
3. Graphs in LATEX- pgfplots
10
4. Drawing in Graphs

λn
0

modes 1 – 3
modes 4 – 6
−10
modes 7 – 11
modes 12 – 16
higher modes
−20
0.5 1 1.5 2 2.5 3 3.5 4
ka
Characteristic numbers of spherical shell3 .
3 M. Masek, J. Rymus, P. Hazdra and M. Capek, “Implementation of the Theory of Characteristic Modes

into Antenna Modeling Tools and Their Benchmarking,” 8th Microwave and Radar Week, Poznan, Poland,
2018.
Michal Mašek Graphics in LATEX 20 / 30
Graphs in LATEX- pgfplots

Why and How to Do That?

I pdfplot: A package for graphs in LATEX.


\usepackage{pgfplots}
I pgfplot manual

Michal Mašek Graphics in LATEX 21 / 30


Graphs in LATEX- pgfplots

Why and How to Do That?

I pdfplot: A package for graphs in LATEX.


\usepackage{pgfplots}
I pgfplot manual

I Perfectly complements Matlab:


I Plot in Matlab:
x = linspace(0, 2*pi, 101);
plot(x, sin(x), x, cos(x));
xlabel(’x’), ylabel(’sin(x),
cos(x)’)

Printscreen of figure from Matlab.

Michal Mašek Graphics in LATEX 21 / 30


Graphs in LATEX- pgfplots

Why and How to Do That?

I pdfplot: A package for graphs in LATEX.


1
\usepackage{pgfplots}
0.8
I pgfplot manual
0.6

I Perfectly complements Matlab: 0.4

I Plot in Matlab:

sin(x), cos(x)
0.2

x = linspace(0, 2*pi, 101); 0

plot(x, sin(x), x, cos(x)); -0.2

xlabel(’x’), ylabel(’sin(x), -0.4

cos(x)’) -0.6

-0.8

-1
0 1 2 3 4 5 6 7
x

Graph in Matlab exported as eps.

Michal Mašek Graphics in LATEX 21 / 30


Graphs in LATEX- pgfplots

Why and How to Do That?

I pdfplot: A package for graphs in LATEX.


\usepackage{pgfplots}
1
I pgfplot manual

I Perfectly complements Matlab: 0.5

sin(x), cos(x)
I Plot in Matlab:
x = linspace(0, 2*pi, 101);
plot(x, sin(x), x, cos(x));
0
xlabel(’x’), ylabel(’sin(x),
cos(x)’) −0.5
I Export to tex tex.
matlab2tikz(’mySinAndCos.tex’);
−1
I matlab2tikz 0 2 4 6
I The content of the .tex file can be: x
I inserted into thesis / paper /
presentation.
I used in standalone document → get Graph exported to LATEX.
the graph as pdf → insert it as image.

Michal Mašek Graphics in LATEX 21 / 30


Graphs in LATEX- pgfplots

matlab2tikz
\begin{axis}[
width=4cm,
I What is in the File? height=3cm,
I Axis setting. at={(0.758in,0.481in)},
scale only axis,
xmin=0,
xmax=7,
xlabel style={font=\color{white!15!black}},
xlabel=x,
ymin=-1,
ymax=1,
ylabel style={font=\color{white!15!black}},
ylabel={sin(x), cos(x)},
axis background/.style={fill=white}
]

% ... other code ...


\end{axis}

Michal Mašek Graphics in LATEX 22 / 30


Graphs in LATEX- pgfplots

matlab2tikz
\definecolor{mycolor1}{rgb}{0.12157,0.47059,0.70588}
\addplot [color=mycolor1, forget plot]
I What is in the File? table[row sep=crcr]{%
I Axis setting. 0 0\\
I Curves setting and data. 0.0628318530717959 0.0627905195293134\\
0.125663706143592 0.125333233564304\\
0.188495559215388 0.187381314585725\\
0.251327412287183 0.248689887164855\\
0.314159265358979 0.309016994374947\\
% ... 101 points of the first curve ...
};

\definecolor{mycolor2}{rgb}{0.20000,0.62745,0.17255}
\addplot [color=mycolor2, forget plot]
table[row sep=crcr]{%
0 1\\
0.0628318530717959 0.998026728428272\\
0.125663706143592 0.992114701314478\\
0.188495559215388 0.982287250728689\\
0.251327412287183 0.968583161128631\\
0.314159265358979 0.951056516295154\\
% ... 101 points of the second curve ...
};

Michal Mašek Graphics in LATEX 22 / 30


Graphs in LATEX- pgfplots

matlab2tikz

I What is in the File?


I Axis setting.
I Curves setting and data.
I Hot to improve it?

Michal Mašek Graphics in LATEX 22 / 30


Graphs in LATEX- pgfplots

matlab2tikz
\documentclass[tikz]{standalone}
% ... some packages imported ...
I What is in the File? \begin{document}
I Axis setting. \definecolor{mycolor1}{rgb}{0.12157,0.47059,0.70588}
I Curves setting and data. \definecolor{mycolor2}{rgb}{0.20000,0.62745,0.17255}
I Hot to improve it? \begin{tikzpicture}
I standalone class – \begin{axis}[%
minimalistic document, pdf % ... axis setting as before ...
only with the figure. ]
I Externalize – data are saved \addplot [color=mycolor1, line width=2.0pt]
table[]{mySinAndCos-1.tsv};
in extenal .tsv ASCI files,
\addlegendentry{data1}
matlab2tikz(’mySinAndCos.tex’,
’standalone’, true, \addplot [color=mycolor2, line width=2.0pt]
table[]{mySinAndCos-2.tsv};
’externalData’, true); \addlegendentry{data2}
\end{axis}
\end{tikzpicture}
\end{document}

Michal Mašek Graphics in LATEX 22 / 30


Graphs in LATEX- pgfplots

Practical Usage – How to Make It better


\tikzstyle{linesAll} = [thick, line join = round, mark
I Generalize as much as possible phase=1, mark repeat=5]
I general tikzstyle for lines,

Michal Mašek Graphics in LATEX 23 / 30


Graphs in LATEX- pgfplots

Practical Usage – How to Make It better


\def\myLineWidth{0.75}
\def\myMarkerLineWidth{0.25}
I Generalize as much as possible \def\myMarkSize{1.4}
I general tikzstyle for lines, \def\myMarkSizeD{0.2}
I tikzstyle for markers, \tikzstyle{markerCirc} = [mark size=\myMarkSize pt,
mark=*, mark options={solid, draw=black, line
width=\myMarkerLineWidth pt}]
\tikzstyle{markerTria} = [mark
size=\myMarkSize+2*\myMarkSizeD pt, mark=triangle*,
mark options={solid, draw=black, line
width=\myMarkerLineWidth pt}]
\tikzstyle{markerSquare} = [mark
size=\myMarkSize-\myMarkSizeD pt, mark=square*, mark
options={solid, draw=black, line
width=\myMarkerLineWidth pt}]
\tikzstyle{markerDiam} = [mark
size=\myMarkSize+\myMarkSizeD pt, mark=diamond*, mark
options={solid, draw=black, line
width=\myMarkerLineWidth pt}]

Michal Mašek Graphics in LATEX 23 / 30


Graphs in LATEX- pgfplots

Practical Usage – How to Make It better


\begin{tikzpicture}
\begin{axis}[%
I Generalize as much as possible width=8 cm,
I general tikzstyle for lines, height=4.5cm,
I tikzstyle for markers, scale only axis,
I Have pre-defined axis. xmin=0,
xmax=6.28,
xlabel={$x$},
ymin=-1,
ymax=1,
ylabel={$\sin x$, $\cos x$},
legend style={at={(axis cs:3,0.45)}, anchor=south west}
]
\end{axis}
\end{tikzpicture}

Michal Mašek Graphics in LATEX 23 / 30


Graphs in LATEX- pgfplots

Practical Usage – How to Make It better


\begin{tikzpicture}
\begin{axis}[%
I Generalize as much as possible width=8 cm,
I general tikzstyle for lines, height=4.5cm,
I tikzstyle for markers, scale only axis,
I Have pre-defined axis. xmin=0,
xmax=6.28,
I Load external data. xlabel={$x$},
ymin=-1,
ymax=1,
ylabel={$\sin x$, $\cos x$},
legend style={at={(axis cs:3,0.45)}, anchor=south
west},
grid = major]
\addplot [linesAll, markerCirc, PairedB]
table[x index=0,y index=1]{mySinAndCos.tsv};

\addplot [linesAll, markerTria, PairedH]


table[x index=0,y index=2]{mySinAndCos.tsv};

\legend{$\sin x$, $\cos x$}


\end{axis}
\end{tikzpicture}
Michal Mašek Graphics in LATEX 23 / 30
Graphs in LATEX- pgfplots

Practical Usage – How to Make It better


\begin{tikzpicture}
\begin{axis}[%
I Generalize as much as possible width=8 cm,
I general tikzstyle for lines, height=4.5cm,
I tikzstyle for markers, scale only axis,
I Have pre-defined axis. xmin=0,
xmax=6.28,
I Load external data. xlabel={$x$},
I Only files with data are changing. ymin=-1,
ymax=1,
ylabel={$\sin x$, $\cos x$},
legend style={at={(axis cs:3,0.45)}, anchor=south
west},
grid = major]
\addplot [linesAll, markerCirc, PairedB]
table[x index=0,y index=1]{mySinAndCos.tsv};

\addplot [linesAll, markerTria, PairedH]


table[x index=0,y index=2]{mySinAndCos.tsv};

\legend{$\sin x$, $\cos x$}


\end{axis}
\end{tikzpicture}
Michal Mašek Graphics in LATEX 23 / 30
Graphs in LATEX- pgfplots

Practical Usage – How to Make It better

I Generalize as much as possible


1
I general tikzstyle for lines,
I tikzstyle for markers, sin x
cos x
I Have pre-defined axis. 0.5

sin x, cos x
I Load external data.
I Only files with data are changing. 0

I matlab2tikz is not needed


anymore: −0.5
x = linspace(0, 2*pi, 101).’;
Data = [x, sin(x), cos(x)]; −1
0 1 2 3 4 5 6
save(’mySinAndCos.tsv’,
x
’Data’, ’-ascii’);
The solution.

Michal Mašek Graphics in LATEX 23 / 30


Drawing in Graphs

Outline

1. Introduction
270

characteristic angle δ n (deg)


2. Figures with TikZ
3. Graphs in LATEX- pgfplots 240

4. Drawing in Graphs 210

180 d W

150
L
120

90
1 2 3 4 5
electrical size ka
Comparison of two tracking methods4 .

4 M. Masek, M. Capek, L. Jelinek and K. Schab, “Modal Crossing Treatment Using Group Theory,” 2019

13th European Conference on Antennas and Propagation (EuCAP), Krakow, Poland, 2019.
Michal Mašek Graphics in LATEX 24 / 30
Drawing in Graphs

Drawing in Plots

I Both methods, TikZ and PGF, can be combined.

Michal Mašek Graphics in LATEX 25 / 30


Drawing in Graphs

Drawing in Plots

I Both methods, TikZ and PGF, can be combined.


I Draw outside axis environment:
I Standard coordinate notation (X, Y).

Michal Mašek Graphics in LATEX 25 / 30


Drawing in Graphs

Drawing in Plots

I Both methods, TikZ and PGF, can be combined.


I Draw outside axis environment:
I Standard coordinate notation (X, Y).
I Draw inside axis environment:
I Axis coordinate system can be used: (axis cs: X, Y)

Michal Mašek Graphics in LATEX 25 / 30


Drawing in Graphs

Drawing in Plots

I Both methods, TikZ and PGF, can be combined.


I Draw outside axis environment:
I Standard coordinate notation (X, Y).
I Draw inside axis environment:
I Axis coordinate system can be used: (axis cs: X, Y)
I This is default notation since pgfplots version 1.11 (Aug 2014).
I Use: \pgfplotsset{compat=newest} for the newest version in header,
then axis cs: can be omitted.

Michal Mašek Graphics in LATEX 25 / 30


Drawing in Graphs

Drawing in Plots

I Both methods, TikZ and PGF, can be combined.


I Draw outside axis environment:
I Standard coordinate notation (X, Y).
I Draw inside axis environment:
I Axis coordinate system can be used: (axis cs: X, Y)
I This is default notation since pgfplots version 1.11 (Aug 2014).
I Use: \pgfplotsset{compat=newest} for the newest version in header,
then axis cs: can be omitted.
I Relative axis coordinate system:
I (rel axis cs: 0, 0) bottom left corner of axis,
I (rel axis cs: 1, 1) top right corner of axis.

Michal Mašek Graphics in LATEX 25 / 30


Drawing in Graphs

Drawing in Plots – Example I.


\begin{tikzpicture}
% ... styles defined on previous slides ...
\begin{axis}[ 1
% ... axis settings ... sin x
] cos x
0.5

sin x, cos x
\addplot [linesAll, markerCirc, PairedB]
table[x index=0,y index=1]{mySinAndCos.tsv}; 0
\addplot [linesAll, markerTria, PairedH]
table[x index=0,y index=2]{mySinAndCos.tsv};
\legend{$\sin x$, $\cos x$} −0.5

\draw[red, ->, thick] (0,0) -- (1,1); −1


\draw[green, ->, dashed, thick] (axis cs: 0 1 2 3 4 5 6
0,0) -- (axis cs: 1,1); x
\draw[cyan, ->, thick] (rel axis cs: 0,0) --
Previously described plot with arrows.
(rel axis cs: 1,1);
\end{axis}
\draw[magenta, ->, thick] (0,0) -- (1,1);
\end{tikzpicture}

Michal Mašek Graphics in LATEX 26 / 30


Drawing in Graphs

Drawing in Plots – Example II.


\begin{tikzpicture}
% ... styles defined on previous slides ...
\begin{axis}[ 1
% ... axis settings ... sin x
] cos x
0.5
% ... add plots as before ...

sin x, cos x
\tikzstyle{highlight} = [fill = red, fill 0
opacity = 0.3, inner sep = 0cm, circle, minimum
size = 0.5cm]
\node[highlight] (A) at (0.7854, 0.7071) {}; −0.5
\node[highlight] (B) at (3.9270, -0.7071) {}; crossing
−1
\node[red, fill = white] (C) at (1, -0.75) 0 1 2 3 4 5 6
{crossing}; x

Previously described plot with arrows.


\draw[->, red, thick] (C.north) -- (A.south);
\draw[->, red, thick] (C.east) -- (B.west);
\end{axis}
\end{tikzpicture}

Michal Mašek Graphics in LATEX 27 / 30


Drawing in Graphs

Advance TikZ – Preview for Nex LATEX Semminar

z
y x

Six bowtie antennas arranged into cubic array2 .

2 M. Masek, M. Capek, L. Jelinek, and K. Schab, “Modal Tracking Based on Group Theory,” submited to

IEEE Trans. Antennas Propag., 2018.


Michal Mašek Graphics in LATEX 28 / 30
Drawing in Graphs

Advance TikZ – Preview for Nex LATEX Semminar

Far-field of radiated structure5 . It requires media9 package, data in u3D.

5 M. Capek, “Source Concept and Its Utilization for the Analysis of Electrically Small

Antennas,” Habilitation lecture, Czech Technical University in Prague, Czech Republic, 2017.
Michal Mašek Graphics in LATEX 28 / 30
Source codes

Source codes

I Memory problems with pdflatex in TeXstudio:


Settings – Build – field with pdflatex:
pdflatex --enable-write18 --extra-mem-bot=10000000 --synctex=1
I Source codes6 of figures used in the presentation:

Cz2 270
l

characteristic angle δ n (deg)


1
ψ2 240
ψ1 210
sin x
cos x
ψ3 σvxz s
0.5

sin x, cos x
180 d W
0
150
d L
ψ4 120 −0.5
ψ5 crossing
90
σvyz 1 2 3 4 5 −1
0 1 2 3 4 5 6
h electrical size ka x

I source code I source code I source code I source code

6 Note that the code is not as perfect as possible. Sometimes a quick result was required instead of making

the code more general.


Michal Mašek Graphics in LATEX 29 / 30
Questions

Questions?
Michal Mašek
michal.masek@fel.cvut.cz

Departmental seminars
May 7 and 14, 2019

version: 1.2, last edit: May 14, 2019


The presentation is downloadable at
I michal-masek.cz

Michal Mašek Graphics in LATEX 30 / 30

You might also like