+ All Categories
Home > Documents > Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten...

Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten...

Date post: 11-Aug-2019
Category:
Upload: truongkiet
View: 214 times
Download: 0 times
Share this document with a friend
80
Grafiken in L A T E X mit Tik Z und PGFPLOTS Eine Einführung Patrick Schulz 12. Februar 2016
Transcript
Page 1: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Grafiken in LATEX mit TikZ und

PGFPLOTSEine Einführung

Patrick Schulz

12. Februar 2016

Page 2: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Begrüßung und Übersicht

Thema

• Grafiken mit TikZ

• Plots (Kurven, Graphen) mit PGFPLOTS

Grafikprogramme

• Matlab, Octave, Gnuplot

• …

• Paint?

Patrick Schulz 2/74

Page 3: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Standard Matlabplot

0 1 2 3 4 5 6−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1Sinus und Cosinus

x [rad]

y []

SinusCosinus

Probleme

• Schriftart

• Kleine Schrift

• Liniendicke

Patrick Schulz 3/74

Page 4: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Standard Matlabplot

0 1 2 3 4 5 6−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1Sinus und Cosinus

x [rad]

y []

SinusCosinus

Probleme

• Schriftart

• Kleine Schrift

• Liniendicke

Patrick Schulz 3/74

Page 5: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

„Schöne“ Grafiken

Probleme

• Schriftart

• Bunte Farben

• Skalierbarkeit

• Schattierungen

Patrick Schulz 4/74

Page 6: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

„Schöne“ Grafiken

Probleme

• Schriftart

• Bunte Farben

• Skalierbarkeit

• Schattierungen

Patrick Schulz 4/74

Page 7: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Programmierbare Grafiken in LATEX

Grafiken in LATEX

+ identische Schriftarten

+ alle LATEX-Befehle verfügbar (z.B. Mathematikmodus)

+ einfaches Anpassen aller Grafiken

- umständlich

- eventuell langsam

Technische Grafiken

• einfache Strukturen

• keine Schnörkel und Dekorationen

Gut Programmierbar

Patrick Schulz 5/74

Page 8: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Sinus und Cosinus

0 1 2 3 4 5 6−1

−0.5

0

0.5

1

x[rad]

y[]

Sinus und Cosinus

Sinus

Cosinus

Patrick Schulz 6/74

Page 9: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Sinus und Cosinus

0 12π

π 32π

2π−1

−0.5

0

0.5

1

x[rad]

y[]

Sinus und Cosinus

Sinus

Cosinus

Patrick Schulz 7/74

Page 10: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ-Grafiken

Beispiel Bändermodell

WV

WC

WF

W

x+ + + + +

-

+

-

+

-

+

-

+

- --

+

-

+

-

+

-

+

-

+

-

+

- - - -

Go

~jn

~jp

pp0

np0

WV

WC

Wi

WF

WFn

WFp

Patrick Schulz 8/74

Page 11: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ-Grafiken

Beispiel Datenpfad

n p d

sub > add 0:0

divmoddiv mod

== <=

1 0

1 2

0

ni 2 2

n_sel p_sel d_sel

add_sel0 add_sel1

sub_sel

n_write p_write d_write

result

s0

s1

s2

s3

Patrick Schulz 9/74

Page 12: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Übertragungsfunction

100 101 102 103 104 105 106 107 108 109 1010−40

−20

0

20

40

60

80

100

fug

f [Hz]

Av[dB]

−360

−300

−240

−180

−120

−60

0

60

allowed phase shift

ϕ[°]

Gain

Phase

Patrick Schulz 10/74

Page 13: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Transientensimulation

0 5 10 15 20 25

−0.5

−0.25

0

0.25

0.5

Vswing = 1 V

Slew Rate

t [ns]

Vout[V]

Patrick Schulz 11/74

Page 14: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Übersicht

TikZ

• Einführung

• Leitfaden mit Beispielen

• Hinweise

PGFPLOTS

• Einführung

• Leitfaden mit Beispielen

• Hinweise

Weitere Informationen

• Allgemeine Hinweise

• Hilfsmittel und Quellen

Patrick Schulz 12/74

Page 15: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Page 16: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Einführung

Hintergrund

• TikZ ist kein Zeichenprogramm

→ Sprache zum Erstellen von Grafiken

• Autor: Till Tantau

• TikZ als Frontend für PGF

• Reguläres LATEX-Paket

Patrick Schulz 14/74

Page 17: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Grundlagen

Verwendung

• \usepackage{tikz}

• Zeichenbefehle innerhalb von

\begin{tikzpicture} ... \end{tikzpicture}

• Zeichnen mit \draw, \fill, \node usw.

• Koordinaten mit (x, y), (phi:r) und weitere

• Pfadoperationen: --, rectangle, circle

• Grundlegende Struktur: \draw (x1, y1) pfadoperation (x2, y2);

• Zeichenbefehle mit Semikolon abschließen

Patrick Schulz 15/74

Page 18: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Grundlagen

Grundlegende Pfadoperationen

\begin{tikzpicture}\draw (0, 0) -- (1, 1) -- (2, 0) -- (0, 0); % Dreieck\draw (3, 0) rectangle (5, 1); % Rechteck\draw (7, 0.5) circle (0.5); % Kreis

\end{tikzpicture}

Patrick Schulz 16/74

Page 19: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Stile für Pfade

\begin{tikzpicture}\draw[red, thick] (0, 0) circle (1);\draw[dashed] (-1, 1) -- (1, -1);

\end{tikzpicture}

Optionen

• Farben

• Linienstile: Dicken und Pfeilspitzen

• Transparenz

• viele, viele weitere

Patrick Schulz 17/74

Page 20: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Stile für Pfade

\begin{tikzpicture}\draw[red, thick] (0, 0) circle (1);\draw[dashed] (-1, 1) -- (1, -1);

\end{tikzpicture}

Optionen

• Farben

• Linienstile: Dicken und Pfeilspitzen

• Transparenz

• viele, viele weitere

Patrick Schulz 17/74

Page 21: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Nodes

Text in Grafiken

• Platzierung mit \node

• Position auf dem aktuellen Pfad, mit at (x, y) oder relativ zu

anderen Koordinaten

• Nodes haben eine Form

• Nodes können benannt werden

• Text in {...} (Nicht optional, kann aber leer sein)

• Syntax: \node[options] at (x, y) (name) { Text };

Patrick Schulz 18/74

Page 22: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

TikZ

Grundlagen – Nodes Beispiel

\begin{tikzpicture}\node { Harder };\node[draw] at (2, 0) (n1) { Better };\node[right=of n1] { Faster };\path (6, 0) node[draw, circle] { Stronger };\draw (0, -2) -- node[above] { Go Crescendolls! } (6, -2);

\end{tikzpicture}

Harder Better Faster Stronger

Go Crescendolls!

Patrick Schulz 19/74

Page 23: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel

Erde und Mond, Flowchart

Erde

Mond~v

~Fg

Drawing to scale.

Is there anything

you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 20/74

Page 24: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Erde

\begin{tikzpicture}\fill (0, 0) circle (0.4); % Erde im Ursprung (0, 0)

\end{tikzpicture}

Wichtig: die internen Koordinaten spielen keine Rolle!

Patrick Schulz 21/74

Page 25: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Mond und Umlaufbahn

\begin{tikzpicture}\fill (0, 0) circle (0.4);\draw[dashed] (0, 0) circle(2); % Umlaufbahn\fill (0, 2) circle (0.2); % Mond auf der Umlaufbahn

\end{tikzpicture}

Patrick Schulz 22/74

Page 26: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Vektorpfeile

\begin{tikzpicture}\fill (0, 0) circle (0.4);\draw[dashed] (0, 0) circle(2);\fill (0, 2) circle (0.2);\draw[->] (-0.2, 2) -- (-0.6, 2); % Bewegungsrichtung\draw[->] (0, 1.8) -- (0, 1.4); % Kraftrichtung

\end{tikzpicture}

Patrick Schulz 23/74

Page 27: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Schönere Pfeilspitzen

\begin{tikzpicture}[>=stealth'] % mit TikZ-Bibliothek 'arrows'\fill (0, 0) circle (0.4);\draw[dashed] (0, 0) circle(2);\fill (0, 2) circle (0.2);\draw[->] (-0.2, 2) -- (-0.6, 2);\draw[->] (0, 1.8) -- (0, 1.4);

\end{tikzpicture}

Patrick Schulz 24/74

Page 28: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Beschriftung der Pfeile

% Code wie zuvor\node[above] at (-0.4, 2) { $\vec{v}$ };\node[right] at (0, 1.6) { $\vec{F_g}$ };

\end{tikzpicture}

~v

~Fg

Patrick Schulz 25/74

Page 29: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Text und Hinweis

% code wie zuvor\node[above] at (-0.4, 2) { $\vec{v}$ };\node[right] at (0, 1.6) { $\vec{F_g}$ };\node at (0.6, 0.6) { Erde };\node at (0.4, 2.4) { Mond };\node[below] at (0, -2) { \emph{Drawing to scale.} };

\end{tikzpicture}

~v

~Fg

Erde

Mond

Drawing to scale.

Patrick Schulz 26/74

Page 30: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Erde und Mond

Gesamter Code

\begin{tikzpicture}[>=stealth']\fill (0, 0) circle (0.4); % Erde\draw[dashed] (0, 0) circle(2); % Umlaufbahn\fill (0, 2) circle (0.2); % Mond\draw[->] (-0.2, 2) -- (-0.6, 2); % Geschwindigkeit\draw[->] (0, 1.8) -- (0, 1.4); % Kraft\node[above] at (-0.4, 2) { $\vec{v}$ }; % Vektor\node[right] at (0, 1.6) { $\vec{F_g}$ }; % Vektor\node at (0.6, 0.6) { Erde }; % Text Erde\node at (0.4, 2.4) { Mond }; % Text Mond% Hinweis:\node[below] at (0, -2) { \emph{Drawing to scale.} };

\end{tikzpicture}

Patrick Schulz 27/74

Page 31: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Zur Erinnerung

Is there anything

you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 28/74

Page 32: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Erster Knoten

\node[draw, rectangle] { Is there anything you should be doing? };

Is there anything you should be doing?

\node[below left=of ...] { Yes };

Die Nodes müssen benannt werden.

Patrick Schulz 29/74

Page 33: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Erster Knoten

\node[draw, rectangle] { Is there anything you should be doing? };

Is there anything you should be doing?

\node[below left=of ...] { Yes };

Die Nodes müssen benannt werden.

Patrick Schulz 29/74

Page 34: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Erster Knoten

\node[draw, rectangle] { Is there anything you should be doing? };

Is there anything you should be doing?

\node[below left=of ...] { Yes };

Die Nodes müssen benannt werden.

Patrick Schulz 29/74

Page 35: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Positionierung und Benennung

Is there anything

you should be doing?

Yes No

Do it. Don’t fucking lie

below left below right

below below

(top)

(yes) (no)

(doit) (lie)

Patrick Schulz 30/74

Page 36: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Restliche Knoten – relative Positionierung

\node[draw, rectangle] (top) { Is there anything you should bedoing? };

\node[draw, rectangle, below left=of top] (yes) { Yes };\node[draw, rectangle, below right=of top] (no) { No };\node[draw, rectangle, below =of yes] (doit) { Do it. };\node[draw, rectangle, below =of no] (lie) { Don't fucking lie };

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 31/74

Page 37: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Abstand zwischen den Knoten

\begin{tikzpicture}[node distance=0cm and 0cm]\node[draw, rectangle] (top) { Is there anything you shouldbe doing? };\node[draw, rectangle, below left=of top] (yes) { Yes };\node[draw, rectangle, below right=of top] (no) { No };\node[draw, rectangle, below =of yes] (doit) { Do it. };\node[draw, rectangle, below =of no] (lie) { Don't fuckinglie };

\end{tikzpicture}

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 32/74

Page 38: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Abstand zwischen den Knoten

\begin{tikzpicture}[node distance=0.75cm and -0.5cm]\node[draw, rectangle] (top) { Is there anything you shouldbe doing? };\node[draw, rectangle, below left=of top] (yes) { Yes };\node[draw, rectangle, below right=of top] (no) { No };\node[draw, rectangle, below =of yes] (doit) { Do it. };\node[draw, rectangle, below =of no] (lie) { Don't fuckinglie };

\end{tikzpicture}

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 33/74

Page 39: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Verbindungen

% nodes wie zuvor\draw[->, >=stealth'] (top) -- (yes);\draw[->, >=stealth'] (top) -- (no);\draw[->, >=stealth'] (yes) -- (doit);\draw[->, >=stealth'] (no) -- (lie);\draw[->, >=stealth'] (lie) -- (doit);

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 34/74

Page 40: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Rechtwinklige Verbindungen

% nodes wie zuvor\draw[->, >=stealth'] (top) |- (yes);\draw[->, >=stealth'] (top) |- (no);\draw[->, >=stealth'] (yes) -- (doit);\draw[->, >=stealth'] (no) -- (lie);\draw[->, >=stealth'] (lie) -- (doit);

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 35/74

Page 41: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Einschub

Nodes und Fixpunkte (anchors)

south

west east

north north east

south east

north west

south west

center

Patrick Schulz 36/74

Page 42: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Rechtwinklige Verbindungen

% nodes wie zuvor\draw[->, >=stealth'] (top.south) -- ++(0, -0.5) -| (yes);\draw[->, >=stealth'] (top.south) -- ++(0, -0.5) -| (no);\draw[->, >=stealth'] (yes) -- (doit);\draw[->, >=stealth'] (no) -- (lie);\draw[->, >=stealth'] (lie) -- (doit);

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 37/74

Page 43: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Runde Ecken

% nodes wie zuvor\draw[->, >=stealth', rounded corners] (top.south) -- ++(0, -0.5)

-| (yes);\draw[->, >=stealth', rounded corners] (top.south) -- ++(0, -0.5)

-| (no);\draw[->, >=stealth'] (yes) -- (doit);\draw[->, >=stealth'] (no) -- (lie);\draw[->, >=stealth'] (lie) -- (doit);

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 38/74

Page 44: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Runde Ecken

\begin{tikzpicture}[

node distance=0.75cm and -0.5cm,rounded corners,>=stealth'

]% code wie zuvor

\end{tikzpicture}

Is there anything you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 39/74

Page 45: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Einschub

Textbreite und Ausrichtung

\node[draw] at (0, 0){ Ein langer Text, der (hoffentlich) umgebrochen wird. };

\node[draw, text width=4cm] at (0, -1.5){ Ein langer Text, der (hoffentlich) umgebrochen wird. };

\node[draw, align=center] at (0, -3){ Ein langer Text, der \\(manuell) umgebrochen wird. };

Ein langer Text, der (hoffentlich) umgebrochen wird.

Ein langer Text, der

(hoffentlich) umgebro-

chen wird.

Ein langer Text, der

(manuell) umgebrochen wird.

Patrick Schulz 40/74

Page 46: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Breite der Nodes

% Einstellungen wie zuvorfont=\small

]\node[

draw,rectangle,align=center

] (top) { Is there anything \\ you should be doing? };% Code wie zuvor

Is there anything

you should be doing?

Yes No

Do it. Don’t fucking lie

Patrick Schulz 41/74

Page 47: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Flowchart

Gesamter Code

\begin{tikzpicture}[

% Einstellungennode distance=0.75cm and -0.5cm,rounded corners,font=\small,>=stealth'

]% Knoten\node[draw, rectangle, align=center]

(top) { Is there anything \\ you should be doing? };\node[draw, rectangle, below left=of top] (yes) { Yes };\node[draw, rectangle, below right=of top] (no) { No };\node[draw, rectangle, below =of yes] (doit) { Do it. };\node[draw, rectangle, below =of no] (lie) { Don't fucking lie };% Verbindungen\draw[->] (top.south) -- ++(0, -0.5) -| (yes);\draw[->] (top.south) -- ++(0, -0.5) -| (no);\draw[->] (yes) -- (doit);\draw[->] (no) -- (lie);\draw[->] (lie) -- (doit);

\end{tikzpicture}

Patrick Schulz 42/74

Page 48: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Hinweise

Einstellungen, Stildefinitionen, …

Global oder lokal?

• Lokale Einstellungen: \draw[...], \node[...] und

\begin{tikzpicture}[...]

• Globale Einstellungen: \tikzset{...}

• Einheitlicher Stil über gesamtes Dokument

• Wesentlich verkürzter Code

• Möglichkeit der Definition eines Stils:\tikzset{

state/.style={draw, rectangle, thick}}% Benutzung:\node[state] { };

Patrick Schulz 43/74

Page 49: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Hinweise

Bibliotheken

Erweiterung der TikZ-Befehle

• positioning, arrows bereits vorgestellt

• calc: Für erweiterte Koordinatenberechnungen (Projektionen,

Schnittpunkte und mehr)

• decorations: Veränderung des Aussehens von Pfaden, zum

Beispiel zufällige Sprünge, Sinuskurven oder Zick-Zack-Linien

• matrix: Definition von mehreren nodes als Einheit

• pattern: Füllen von Flächen mit Strukturen

Viele nützliche Bibliotheken, unbedingt nutzen!

Patrick Schulz 44/74

Page 50: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Page 51: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Grundlagen

Übersicht

• Basiert auf TikZ/PGF

• Umgebungen für verschiedene Koordinatensysteme: Linear,

Halb- / Volllogarithmisch, Polar, Smithcharts, …

• Vielzahl von verfügbaren Dateneingaben

• Datenverarbeitung wie Regression und Filterung möglich

• Zeichnungen mit Hilfe von TikZ innerhalb Plots

• Sehr viele Optionen, aber gute Standardeinstellungen, hierdurch

einfache Anwendung

Patrick Schulz 46/74

Page 52: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

PGFPLOTS

Grundlagen

Verwendung

• Wahl des Koordinatensystems durch Umgebung: \begin{axis} ...

Umgebung innerhalb tikzpicture

• Erzeugen von Kurven durch \addplot

• Wahl der Datenquelle:

I Funktionen (expression)I Koordinaten (coordinates)I externe Daten (table)

• Achsenbeschriftung durch xlabel, ylabel, title, …

• Legenden durch \legend{...}

Patrick Schulz 47/74

Page 53: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Das Ziel

0 1 2 3 4 5 6

0.25

0.5

0.75

1

1.25

U0 ·(1− e−x

)

U0 ·(1− e−x · cos(200x)

)“Settled” Area

Uout

U0

Patrick Schulz 48/74

Page 54: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Erster Versuch

\begin{axis} % lineares Koordinatensystem% Sprung erster Ordnung\addplot expression { 1 - exp(-x) };% Sprung zweiter Ordnung\addplot expression { 1 - exp(-x) * cos(200*x) };

\end{axis}

Patrick Schulz 49/74

Page 55: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Erster Versuch

\begin{axis} % lineares Koordinatensystem% Sprung erster Ordnung\addplot expression { 1 - exp(-x) };% Sprung zweiter Ordnung\addplot expression { 1 - exp(-x) * cos(200*x) };

\end{axis}

−6 −4 −2 0 2 4 6

−100

0

100

Patrick Schulz 50/74

Page 56: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Anzahl der Punkte

\begin{axis}[samples=200] % lineares Koordinatensystem% Sprung erster Ordnung\addplot expression { 1 - exp(-x) };% Sprung zweiter Ordnung\addplot expression { 1 - exp(-x) * cos(200*x) };

\end{axis}

−6 −4 −2 0 2 4 6

−100

0

100

Patrick Schulz 51/74

Page 57: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Beschränkung der x-Koordinate

\begin{axis}[samples=200, domain=0:7]% Sprung erster Ordnung\addplot expression { 1 - exp(-x) };% Sprung zweiter Ordnung\addplot expression { 1 - exp(-x) * cos(200*x) };

\end{axis}

0 1 2 3 4 5 6 7

0

0.5

1

1.5

Patrick Schulz 52/74

Page 58: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Achsenbeschriftung und Gitter

\begin{axis}[samples=200, domain=0:7, grid,xlabel={$\frac{t}{\tau}$},ylabel={$\frac{U_{out}}{U_0}$}

]\addplot expression { 1 - exp(-x) };\addplot expression { 1 - exp(-x) * cos(200*x) };

\end{axis}

0 1 2 3 4 5 6 7

0

0.5

1

1.5

Uout

U0

Patrick Schulz 53/74

Page 59: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Art der Achsen

\begin{axis}[% wie zuvoraxis x line=bottom, axis y line=left

]\addplot expression { 1 - exp(-x) };\addplot expression { 1 - exp(-x) * cos(200*x) };

\end{axis}

0 1 2 3 4 5 6 70

0.5

1

Uout

U0

Patrick Schulz 54/74

Page 60: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Einschub

Koordinatensysteme

\addplot[red, domain=0:10] expression { x };\draw (axis cs:5, 0) -- (axis cs: 5, 7);\draw (2, 1) -- (4, 8); % implizit\draw (axis description cs: 0, -0.2)

-- (axis description cs: 1, -0.2);\node[right] at (axis description cs:1, 1) { oben rechts};

0 2 4 6 8 10

0

5

10oben rechts

Patrick Schulz 55/74

Page 61: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Füllfläche

% Einstellungen wie zuvor\addplot expression { 1 - exp(-x) };\addplot expression { 1 - exp(-x) * cos(200*x) };\fill[blue, opacity=0.2] (0, 0.95) rectangle (7, 1.05);

0 1 2 3 4 5 6 70

0.5

1

Uout

U0

Patrick Schulz 56/74

Page 62: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Nodes in Plots

% Einstellungen und Plots wie zuvor\node[below] at (2, 0.5) (p1) { $U_0 \cdot (1 - e^{-x})$ };\node[right] at (2.5, 1.3) (p2) { $U_0 \cdot (1 - e^{-x}\cdot \cos(200x))$ };\draw[->] (p1) -- +(-0.4, 0.4);\draw[->] (p2.west) -- +(-1.1, -0.3);

0 1 2 3 4 5 6 70

0.5

1

U0 · (1− e−x)

U0 · (1− e−x · cos(200x))

Uout

U0

Patrick Schulz 57/74

Page 63: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Nodes in Plots – der bessere Weg

\node[pin=angle:text] { };

% Einstellungen und Plots wie zuvor\node[pin=-60:{$U_0 \cdot (1 - e^{-x})$}]

at (1.5, 0.75) {};\node[pin=30:{$U_0 \cdot (1 - e^{-x} \cdot \cos(200x))$}]

at (1.5, 1) {};\node[pin=-90:{Settled Area}] at (6, 1) { };

0 1 2 3 4 5 6 70

0.5

1

U0 · (1− e−x)

U0 · (1− e−x · cos(200x))

Settled Area

Uout

U0

Patrick Schulz 58/74

Page 64: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Nodes in Plots – der bessere Weg

\node[pin=angle:text] { };

% Einstellungen und Plots wie zuvor\node[pin=-60:{$U_0 \cdot (1 - e^{-x})$}]

at (1.5, 0.75) {};\node[pin=30:{$U_0 \cdot (1 - e^{-x} \cdot \cos(200x))$}]

at (1.5, 1) {};\node[pin=-90:{Settled Area}] at (6, 1) { };

0 1 2 3 4 5 6 70

0.5

1

U0 · (1− e−x)

U0 · (1− e−x · cos(200x))

Settled Area

Uout

U0

Patrick Schulz 58/74

Page 65: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Platzierung der Achsenbeschriftungen

% Einstellungen wie zuvorx label style={at={(axis description cs:1, 0)}, right},y label style={at={(axis description cs:0, 1)}, left,rotate=-90}

0 1 2 3 4 5 6 70

0.5

1

U0 · (1− e−x)

U0 · (1− e−x · cos(200x))

Settled Area

Uout

U0

Patrick Schulz 59/74

Page 66: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Beispiel: Sprungantwort

Der gesamte Code

\begin{axis}[

grid,grid style={semithick, densely dotted},xlabel={$\frac{t}{\tau}$},ylabel={$\frac{U_{out}}{U_0}$},axis x line=bottom,axis y line=left,xtick={0, 1, 2, 3, 4, 5, 6},ytick={0.25, 0.5, 0.75, 1, 1.25},x label style={at={(axis description cs:1, 0)}, below},y label style={at={(axis description cs:0, 1)}, left, rotate=-90},width=0.9\textwidth,height=0.9\textheight

]% Plots wie zuvor\end{axis}

Patrick Schulz 60/74

Page 67: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Datenquellen

Expression

\begin{axis}\addplot expression { x^2 + 1 };

\end{axis}

−6 −4 −2 0 2 4 6

0

10

20

Patrick Schulz 61/74

Page 68: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Datenquellen

Coordinates

\begin{axis}\addplot coordinates { (0, 0) (1, 1) (2, 4) (3, 9) (4, 16) };

\end{axis}

0 1 2 3 4

0

5

10

15

Patrick Schulz 62/74

Page 69: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Datenquellen

Table

\begin{axis}\addplot table[x=x, y=dist] {table_example.dat};\addplot table[x index=0, y index=2] {table_example.dat};

\end{axis}

−6 −4 −2 0 2 4 6

0

0.2

0.4

0.6

0.8

1

Patrick Schulz 63/74

Page 70: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Datenquellen

Table – Dateistruktur

x dist dist2-5.00 0.08 3.72-4.89 0.09 6.14-4.79 0.10 1.00-4.69 0.11 1.61-4.59 0.12 2.58-4.49 0.13 4.09-4.39 0.14 6.42-4.29 0.15 9.95

x,dist,dist2-5.00,0.08,3.72-4.89,0.09,6.14-4.79,0.10,1.00-4.69,0.11,1.61-4.59,0.12,2.58-4.49,0.13,4.09-4.39,0.14,6.42-4.29,0.15,9.95

Optionen

• table[x=name], table[y=name]

• table[x index=number], table[y index=number]

• table[col sep=space], table[col sep=comma]

Patrick Schulz 64/74

Page 71: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Hinweise

Globale Einstellungen

Farben, Größen, Liniendicken …

• \pgfplotsset: Analog zu \tikzset

• Einheitliches Aussehen aller Graphen

• Wichtige Optionen:

I width und heightI cycle listI grid style, every axis plot, …

Patrick Schulz 65/74

Page 72: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Hinweise

Globale Einstellungen

Vorschlag

\pgfplotsset{every axis/.append style={grid, width=0.6\textwidth, height=5cm},grid style={densely dotted, thick},every axis plot/.append style={no markers, thick},label style={font=\small},tick label style={font=\small},legend pos={outer north east},cycle list={red, green, cyan, yellow}

}

Graphen können hierdurch sehr einfach erzeugt werden

\begin{axis}[xlabel={$x$},ylabel={$y$}

]\addplot table {data.dat};

\end{axis}

Patrick Schulz 66/74

Page 73: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Typische Fehler und Probleme

• Table-Eingabedatei ohne Dateiendung: Annahme der Endung

.texDateiendung verwenden, z.B. .txt, .dat, …

• Zeichnungen außerhalb des Graphen nicht sichtbar

Standardmäßiges Clipping: \begin{axis}[clip=false]

• Legende einiger Plots in Graph

Ignorieren einzelner Plots: \addplot[forget plot]

• Zwei y-Achsen in einem Graph

Verwendung zweier axis-Umgebungen, siehe Handbuch (Two

Ordinates (y axis) or Multiple Axes)

Patrick Schulz 67/74

Page 74: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Weitere Informationen

Page 75: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

tikzexternalize

Probleme

• lange Übersetzungszeit (meine Bachelorarbeit: ca. eine Minute)

• auch nicht veränderte Grafiken müssen neu gesetzt werden

Lösung: tikzexternalize

• Export aller TikZ-Grafiken

• Import der Grafiken als PDF bei Übersetzung des Dokuments

• Automatische Erkennung von Veränderungen

• Einfache Verwendung:\usetikzlibrary{external}% bzw.\usepgfplotslibrary{external}\tikzexternalize

• externe Programme erlauben: pdflatex -shell-escape

Patrick Schulz 69/74

Page 76: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Einbinden hässlicher Plots

Quelle

Patrick Schulz 70/74

Page 77: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Einbinden hässlicher Plots

Ergebnis

10−1 100 101

100

101h11

h12

h21

h22

Ic [mA]

hije

h-Paramter in Abhängigkeit des Kollektorstroms Ic

Patrick Schulz 71/74

Page 78: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Tipps und Hinweise

TikZ und PGFPLOTS

Tipps

• Gute Tutorials in den Handbüchern

• explizite Koordinaten vermeiden

• Erweiterungspakete: TikZ-Timingdiagramme, tcolorbox(Beispiele in diesen Folien)

Hinweise

• Verwendete PGFPLOTS-Version: 1.12 (\pgfplotsset{compat=1.12})

• Verwendete TikZ-Version: 3.0.0

Patrick Schulz 72/74

Page 79: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Informationsquellen

• TikZ-Handbuch

• PGFPLOTS-Handbuch

• Stackoverflow: tex.stackexchange.com• www.texample.net• Email an mich: [email protected]

Patrick Schulz 73/74

Page 80: Grafiken in LaTeX mit TikZ und pgfplots - Eine Einführung · Flowchart AbstandzwischendenKnoten \begin{tikzpicture}[node distance=0cm and 0cm] \node[draw, rectangle] (top) { Is

Ende

Vielen Dank für die Aufmerksamkeit!

Fragen?

Patrick Schulz 74/74


Recommended