๊ณ ๊ธ TikZ ๋ฐ PGFPlots(Advanced TikZ & PGFPlots)
๊ณ ๊ธ TikZ ๋ฐ PGFPlots(Advanced TikZ & PGFPlots)¶
์ฃผ์ : LaTeX ๋ ์จ: 16๊ฐ ์ค 11๋ฒ์งธ ์ ์์ง์: TikZ ๊ธฐ์ด(๋ ์จ 10), ๊ธฐ๋ณธ ์ํ ๋ชฉํ: ๊ณ ๊ธ TikZ ๊ธฐ๋ฒ ์๋ฌ ๋ฐ ์ถํ ํ์ง์ ๋ฐ์ดํฐ ์๊ฐํ์ ๋ณต์กํ ๋ค์ด์ด๊ทธ๋จ ์์ฑ์ ์ํ PGFPlots ํ์ต
์๊ฐ¶
TikZ ๊ธฐ์ด๋ฅผ ๋ฐํ์ผ๋ก ์ด ๋ ์จ์ ์ ๊ตํ ๊ทธ๋ํฝ์ ๋ง๋ค๊ธฐ ์ํ ๊ณ ๊ธ ๊ธฐ๋ฒ์ ๋ค๋ฃน๋๋ค. ๋ฐ์ดํฐ ์๊ฐํ๋ฅผ ์ํ PGFPlots, foreach ๋ฃจํ, ํธ๋ฆฌ, ์ฅ์, ํจํด๊ณผ ๊ฐ์ ๊ณ ๊ธ TikZ ๊ธฐ๋ฅ ๋ฐ ์ ๊ฒฝ๋ง, ์ํ ๊ธฐ๊ณ, ์ถํ ํ์ง์ ํ๋กฏ๊ณผ ๊ฐ์ ๋ณต์กํ ๋ค์ด์ด๊ทธ๋จ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์๋๋ค.
PGFPlots ํจํค์ง¶
PGFPlots๋ TikZ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ถ๋์์ผ๋ฉฐ ์ํ ํจ์์ ๋ฐ์ดํฐ์ ๊ณ ํ์ง ํ๋กฏ ์์ฑ์ ์ ๋ฌธ์ผ๋ก ํฉ๋๋ค.
PGFPlots ๋ก๋ํ๊ธฐ¶
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} % Use latest compatibility version
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
ํจ์ ํ๋กฏ(Function Plots)¶
๊ธฐ๋ณธ ํจ์ ํ๋กํ ¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
title={Quadratic Function}
]
\addplot[blue, thick] {x^2};
\end{axis}
\end{tikzpicture}
์ ์์ญ๊ณผ ์ํ(Domain and Samples)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
domain=-5:5,
samples=100
]
% Few samples (choppy)
\addplot[red, samples=10] {sin(deg(x))};
% Many samples (smooth)
\addplot[blue, thick, samples=100] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
์ฌ๋ฌ ํจ์(Multiple Functions)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
domain=-2:2,
legend pos=north west
]
\addplot[blue, thick] {x^2};
\addlegendentry{$x^2$}
\addplot[red, thick] {x^3};
\addlegendentry{$x^3$}
\addplot[green, thick] {exp(x)};
\addlegendentry{$e^x$}
\end{axis}
\end{tikzpicture}
์ํ ํจ์(Mathematical Functions)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
domain=0:10,
legend pos=outer north east
]
\addplot[blue] {sin(deg(x))};
\addlegendentry{$\sin(x)$}
\addplot[red] {cos(deg(x))};
\addlegendentry{$\cos(x)$}
\addplot[green] {exp(-x/5)*sin(deg(x))};
\addlegendentry{$e^{-x/5}\sin(x)$}
\end{axis}
\end{tikzpicture}
๋ฐ์ดํฐ ํ๋กฏ(Data Plots)¶
์ขํ ํ๋กํ ¶
\begin{tikzpicture}
\begin{axis}[
xlabel=Time (s),
ylabel=Temperature (ยฐC),
title={Temperature vs. Time}
]
\addplot coordinates {
(0, 20)
(1, 25)
(2, 32)
(3, 38)
(4, 42)
(5, 45)
};
\end{axis}
\end{tikzpicture}
ํ ์ด๋ธ์์ ํ๋กํ ¶
% First create data file: data.dat
% x y
% 0 0
% 1 1
% 2 4
% 3 9
% 4 16
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$
]
\addplot table {data.dat};
\end{axis}
\end{tikzpicture}
์ธ๋ผ์ธ ํ ์ด๋ธ ๋ฐ์ดํฐ¶
\begin{tikzpicture}
\begin{axis}[
xlabel=Month,
ylabel=Sales (k\$),
symbolic x coords={Jan, Feb, Mar, Apr, May},
xtick=data
]
\addplot table {
x y
Jan 23
Feb 28
Mar 35
Apr 32
May 40
};
\end{axis}
\end{tikzpicture}
ํ๋กฏ ์คํ์ผ(Plot Styles)¶
์ ํ๋กฏ(Line Plots)¶
\begin{tikzpicture}
\begin{axis}
\addplot[blue, thick] coordinates {(0,0) (1,1) (2,4) (3,9)};
\addplot[red, dashed] coordinates {(0,0) (1,2) (2,3) (3,5)};
\addplot[green, dotted, ultra thick] coordinates {(0,1) (1,1.5) (2,2) (3,3)};
\end{axis}
\end{tikzpicture}
์ฐ์ ๋(Scatter Plots)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=Height (cm),
ylabel=Weight (kg),
title={Height vs. Weight}
]
\addplot[
only marks,
mark=*,
mark size=2pt,
color=blue
] coordinates {
(160, 55) (165, 60) (170, 65) (175, 70) (180, 75)
(162, 58) (168, 63) (172, 68) (177, 72) (182, 78)
};
\end{axis}
\end{tikzpicture}
๋ง๋ ์ฐจํธ(Bar Charts)¶
\begin{tikzpicture}
\begin{axis}[
ybar,
xlabel=Product,
ylabel=Sales,
symbolic x coords={A, B, C, D, E},
xtick=data,
nodes near coords,
bar width=20pt
]
\addplot coordinates {(A,45) (B,62) (C,38) (D,55) (E,70)};
\end{axis}
\end{tikzpicture}
์์ญ ํ๋กฏ(Area Plots)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
domain=0:10
]
\addplot[fill=blue!20, draw=blue, thick] {sin(deg(x))} \closedcycle;
\end{axis}
\end{tikzpicture}
ํ์คํ ๊ทธ๋จ(Histogram)¶
\begin{tikzpicture}
\begin{axis}[
ybar interval,
xlabel=Value Range,
ylabel=Frequency
]
\addplot coordinates {
(0,5) (1,8) (2,12) (3,15) (4,18) (5,14) (6,10) (7,6) (8,3) (9,0)
};
\end{axis}
\end{tikzpicture}
์ฌ๋ฌ ์ถ(Multiple Axes)¶
๋ฒ๋ก ์ปค์คํฐ๋ง์ด์ง(Legend Customization)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
legend pos=north west,
legend style={
fill=white,
fill opacity=0.8,
draw opacity=1,
text opacity=1
}
]
\addplot[blue] {x};
\addplot[red] {x^2};
\addplot[green] {x^3};
\legend{Linear, Quadratic, Cubic}
\end{axis}
\end{tikzpicture}
์ถ ๋ ์ด๋ธ๊ณผ ์ ๋ชฉ(Axis Labels and Titles)¶
\begin{tikzpicture}
\begin{axis}[
title={Exponential Growth},
xlabel={Time (years)},
ylabel={Population (millions)},
xlabel style={font=\bfseries},
ylabel style={font=\bfseries},
title style={font=\Large\bfseries}
]
\addplot[blue, thick, domain=0:10] {exp(0.3*x)};
\end{axis}
\end{tikzpicture}
๊ฒฉ์ ์ปค์คํฐ๋ง์ด์ง(Grid Customization)¶
\begin{tikzpicture}
\begin{axis}[
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt, draw=gray!50},
minor tick num=5
]
\addplot[blue, thick, domain=0:10] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
3D ํ๋กฏ(3D Plots)¶
๊ธฐ๋ณธ 3D ํ๋กฏ¶
\begin{tikzpicture}
\begin{axis}[
view={60}{30},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$
]
\addplot3[
surf,
domain=-2:2,
samples=20
] {x^2 + y^2};
\end{axis}
\end{tikzpicture}
๋ฉ์ ํ๋กฏ(Mesh Plot)¶
\begin{tikzpicture}
\begin{axis}[
view={45}{45},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$
]
\addplot3[
mesh,
domain=-2:2,
samples=15,
colormap/cool
] {sin(deg(x)) * cos(deg(y))};
\end{axis}
\end{tikzpicture}
ํ๋ฉด ํ๋กฏ(Surface Plot)¶
\begin{tikzpicture}
\begin{axis}[
view={120}{30},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
colorbar
]
\addplot3[
surf,
shader=interp,
domain=-3:3,
samples=30
] {exp(-x^2-y^2)};
\end{axis}
\end{tikzpicture}
๋งค๊ฐ๋ณ์ 3D ํ๋กฏ(Parametric 3D Plot)¶
\begin{tikzpicture}
\begin{axis}[
view={60}{30},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$
]
\addplot3[
domain=0:6*pi,
samples=200,
samples y=0,
thick,
blue
] ({cos(deg(x))}, {sin(deg(x))}, {x});
\end{axis}
\end{tikzpicture}
์ค์ฐจ ๋ง๋(Error Bars)¶
\begin{tikzpicture}
\begin{axis}[
xlabel=Measurement,
ylabel=Value,
error bars/y dir=both,
error bars/y explicit
]
\addplot[
blue,
mark=*,
error bars/.cd,
y dir=both,
y explicit
] coordinates {
(1, 5) +- (0, 0.5)
(2, 7) +- (0, 0.8)
(3, 6) +- (0, 0.6)
(4, 8) +- (0, 0.9)
(5, 9) +- (0, 0.7)
};
\end{axis}
\end{tikzpicture}
ํ ์ด๋ธ์ด ์๋ ์ค์ฐจ ๋ง๋¶
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$y$,
error bars/y dir=both,
error bars/y explicit
]
\addplot[
red,
mark=square*,
error bars/.cd,
y dir=both,
y explicit
] table[
x=x,
y=y,
y error=yerr
] {
x y yerr
1 2 0.3
2 4 0.5
3 5 0.4
4 7 0.6
5 8 0.5
};
\end{axis}
\end{tikzpicture}
TikZ Foreach¶
\foreach ๋ช
๋ น์ ๋ฐ๋ณต์ ์ธ ๊ทธ๋ฆฌ๊ธฐ๋ฅผ ์ํ ๋ฃจํ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.
๊ธฐ๋ณธ Foreach¶
\begin{tikzpicture}
\foreach \x in {0,1,2,3,4,5}
\draw (\x,0) circle (0.2);
\end{tikzpicture}
๋ฒ์ ํ๊ธฐ๋ฒ(Range Notation)¶
\begin{tikzpicture}
% Draw grid of circles
\foreach \x in {0,...,5}
\foreach \y in {0,...,3}
\draw (\x,\y) circle (0.15);
\end{tikzpicture}
์ฌ๋ฌ ๋ณ์(Multiple Variables)¶
\begin{tikzpicture}
\foreach \x/\y/\color in {0/0/red, 1/1/blue, 2/0.5/green, 3/1.5/orange}
\fill[\color] (\x,\y) circle (0.2);
\end{tikzpicture}
๊ณ์ฐ์ด ์๋ Foreach¶
\begin{tikzpicture}
\foreach \angle in {0,30,...,330}
\draw (0,0) -- (\angle:2) node[circle, fill, inner sep=2pt] {};
\end{tikzpicture}
๋ณต์กํ ์์ : ๊ทน์ขํ ๊ฒฉ์¶
\begin{tikzpicture}
% Radial lines
\foreach \angle in {0,30,...,330}
\draw[gray] (0,0) -- (\angle:3);
% Concentric circles
\foreach \radius in {0.5,1,...,3}
\draw[gray] (0,0) circle (\radius);
% Labels
\foreach \angle/\label in {0/0ยฐ, 90/90ยฐ, 180/180ยฐ, 270/270ยฐ}
\node at (\angle:3.3) {\label};
\end{tikzpicture}
ํธ๋ฆฌ(Trees)¶
TikZ๋ ๊ฐ๋ ฅํ ํธ๋ฆฌ ๊ทธ๋ฆฌ๊ธฐ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
๊ธฐ๋ณธ ํธ๋ฆฌ¶
\begin{tikzpicture}[
level distance=1.5cm,
level 1/.style={sibling distance=3cm},
level 2/.style={sibling distance=1.5cm}
]
\node {Root}
child {node {Left}
child {node {LL}}
child {node {LR}}
}
child {node {Right}
child {node {RL}}
child {node {RR}}
};
\end{tikzpicture}
์คํ์ผ์ด ์ ์ฉ๋ ํธ๋ฆฌ¶
\begin{tikzpicture}[
level distance=1.5cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=2cm},
every node/.style={circle, draw, fill=blue!20, minimum size=8mm}
]
\node {A}
child {node {B}
child {node {D}}
child {node {E}}
}
child {node {C}
child {node {F}}
child {node {G}}
};
\end{tikzpicture}
ํธ๋ฆฌ ์ฑ์ฅ ๋ฐฉํฅ(Tree Growing Directions)¶
\begin{tikzpicture}[
grow=right,
level distance=2cm,
level 1/.style={sibling distance=2cm},
every node/.style={rectangle, draw, minimum width=2cm, minimum height=8mm}
]
\node {Root}
child {node {Child 1}}
child {node {Child 2}}
child {node {Child 3}};
\end{tikzpicture}
๊ฒฐ์ ํธ๋ฆฌ(Decision Tree)¶
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[
level distance=2cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=2cm},
decision/.style={diamond, draw, fill=orange!20, aspect=2},
outcome/.style={rectangle, draw, fill=blue!20}
]
\node[decision] {Test}
child {node[outcome] {Positive}
child {node[outcome] {A}}
child {node[outcome] {B}}
}
child {node[outcome] {Negative}
child {node[outcome] {C}}
child {node[outcome] {D}}
};
\end{tikzpicture}
\end{document}
๊ทธ๋ํ(Graphs)¶
๋ ๋ณต์กํ ๊ทธ๋ํ ๊ตฌ์กฐ๋ฅผ ์ํด์๋ graphs ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ธ์.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\graph[tree layout, nodes={circle, draw}] {
A -> {B, C, D},
B -> {E, F},
C -> G,
D -> {H, I}
};
\end{tikzpicture}
\end{document}
์ฅ์(Decorations)¶
์ฅ์์ ๊ฒฝ๋ก์ ์๊ฐ์ ํจ๊ณผ๋ฅผ ์ถ๊ฐํฉ๋๋ค.
์ฅ์ ๋ก๋ํ๊ธฐ¶
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, decorations.pathreplacing}
Snake ์ฅ์¶
\begin{tikzpicture}
\draw (0,2) -- (4,2);
\draw[decorate, decoration=snake] (0,1) -- (4,1);
\draw[decorate, decoration={snake, amplitude=2mm}] (0,0) -- (4,0);
\end{tikzpicture}
Brace ์ฅ์¶
\begin{tikzpicture}
\draw (0,0) rectangle (4,2);
\draw[decorate, decoration={brace, amplitude=5pt}]
(0,2) -- (4,2) node[midway, above=5pt] {Width};
\draw[decorate, decoration={brace, amplitude=5pt, mirror}]
(0,0) -- (0,2) node[midway, left=5pt] {Height};
\end{tikzpicture}
Zigzag ๋ฐ ๊ธฐํ ์ฅ์¶
\begin{tikzpicture}
\draw[decorate, decoration=zigzag] (0,3) -- (4,3);
\draw[decorate, decoration=saw] (0,2) -- (4,2);
\draw[decorate, decoration=coil] (0,1) -- (4,1);
\draw[decorate, decoration={random steps, segment length=3mm}] (0,0) -- (4,0);
\end{tikzpicture}
ํจํด(Patterns)¶
๋ฐ๋ณต ํจํด์ผ๋ก ์์ญ์ ์ฑ์๋๋ค.
ํจํด ๋ก๋ํ๊ธฐ¶
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
๊ธฐ๋ณธ ํจํด¶
\begin{tikzpicture}
\fill[pattern=dots] (0,0) rectangle (2,2);
\fill[pattern=horizontal lines] (3,0) rectangle (5,2);
\fill[pattern=vertical lines] (6,0) rectangle (8,2);
\fill[pattern=crosshatch] (9,0) rectangle (11,2);
\end{tikzpicture}
ํจํด ์์¶
\begin{tikzpicture}
\fill[pattern=dots, pattern color=red] (0,0) rectangle (2,2);
\fill[pattern=north east lines, pattern color=blue] (3,0) rectangle (5,2);
\fill[pattern=grid, pattern color=green] (6,0) rectangle (8,2);
\end{tikzpicture}
๋ ์ด์ด(Layers)¶
๋ ์ด์ด๋ ๊ทธ๋ฆฌ๊ธฐ ์์๋ฅผ ์ ์ดํฉ๋๋ค.
\documentclass{article}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{tikzpicture}
% Main layer (default)
\fill[blue] (0,0) rectangle (2,2);
% Background layer
\begin{pgfonlayer}{background}
\fill[red] (-0.5,-0.5) rectangle (2.5,2.5);
\end{pgfonlayer}
% Foreground layer
\begin{pgfonlayer}{foreground}
\node[circle, fill=yellow, minimum size=1cm] at (1,1) {Top};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
Spy: ๋๋ณด๊ธฐ ํจ๊ณผ¶
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}[spy using outlines={circle, magnification=4, size=2cm, connect spies}]
% Main graphic
\draw[help lines] (0,0) grid (5,5);
\fill[red] (2.5,2.5) circle (0.1);
% Spy on a region
\spy[blue] on (2.5,2.5) in node at (7,2.5);
\end{tikzpicture}
\end{document}
External: TikZ ๊ทธ๋ฆผ ์บ์ฑ¶
ํฐ ๋ฌธ์์ ๊ฒฝ์ฐ ๋ ๋น ๋ฅธ ์ปดํ์ผ์ ์ํด TikZ ๊ทธ๋ฆผ์ ๋ณ๋๋ก ์ปดํ์ผํฉ๋๋ค.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/] % Save to tikz/ folder
\begin{document}
\begin{tikzpicture}
% Complex graphic here
\draw (0,0) grid (5,5);
\end{tikzpicture}
\end{document}
๋ค์ ๋ช
๋ น์ผ๋ก ์ปดํ์ผ: pdflatex -shell-escape document.tex
ํ๋ก ๋ค์ด์ด๊ทธ๋จ(Circuit Diagrams) (๊ฐ๋ต)¶
circuitikz ํจํค์ง๋ ์ ๊ธฐ ํ๋ก๋ฅผ ์ํด TikZ๋ฅผ ํ์ฅํฉ๋๋ค.
\documentclass{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,0) to[battery] (0,2)
to[resistor] (2,2)
to[lamp] (2,0)
to[short] (0,0);
\end{circuitikz}
\end{document}
๋ณต์กํ ์์ ¶
์ถํ ํ์ง ํจ์ ํ๋กฏ¶
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
height=8cm,
xlabel={$x$},
ylabel={$f(x)$},
title={Comparison of Activation Functions},
legend pos=south east,
grid=major,
grid style={dashed, gray!30},
axis lines=middle,
axis line style={->, >=stealth},
xmin=-5, xmax=5,
ymin=-1.5, ymax=1.5,
domain=-5:5,
samples=200,
every axis plot/.append style={thick}
]
% Sigmoid
\addplot[blue] {1/(1+exp(-x))};
\addlegendentry{Sigmoid}
% Tanh
\addplot[red] {tanh(x)};
\addlegendentry{tanh}
% ReLU
\addplot[green, samples=100] {max(0,x)};
\addlegendentry{ReLU}
\end{axis}
\end{tikzpicture}
\end{document}
์ ๊ฒฝ๋ง ๋ค์ด์ด๊ทธ๋จ(Neural Network Diagram)¶
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
neuron/.style={circle, draw, fill=blue!20, minimum size=1cm},
connection/.style={->, >=stealth, thick}
]
% Input layer
\node[neuron] (i1) at (0,2) {$x_1$};
\node[neuron] (i2) at (0,0) {$x_2$};
% Hidden layer
\node[neuron] (h1) at (3,3) {$h_1$};
\node[neuron] (h2) at (3,1.5) {$h_2$};
\node[neuron] (h3) at (3,0) {$h_3$};
% Output layer
\node[neuron] (o1) at (6,1.5) {$y$};
% Connections
\foreach \i in {1,2}
\foreach \h in {1,2,3}
\draw[connection] (i\i) -- (h\h);
\foreach \h in {1,2,3}
\draw[connection] (h\h) -- (o1);
% Labels
\node[above=1cm of i1] {Input Layer};
\node[above=1cm of h2] {Hidden Layer};
\node[above=1cm of o1] {Output Layer};
\end{tikzpicture}
\end{document}
์ํ ๊ธฐ๊ณ(State Machine)¶
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows.meta}
\begin{document}
\begin{tikzpicture}[
>=Stealth,
node distance=3cm,
on grid,
auto,
state/.style={circle, draw, minimum size=1.5cm}
]
% States
\node[state, initial] (q0) {$q_0$};
\node[state, right=of q0] (q1) {$q_1$};
\node[state, accepting, right=of q1] (q2) {$q_2$};
% Transitions
\path[->]
(q0) edge[bend left] node {a} (q1)
(q1) edge[bend left] node {b} (q0)
(q1) edge node {c} (q2)
(q2) edge[loop right] node {a,b,c} ();
\end{tikzpicture}
\end{document}
๋ฐ์ดํฐ ์๊ฐํ: ์ฌ๋ฌ ํ๋กฏ(Data Visualization: Multiple Plots)¶
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=14cm,
height=8cm,
xlabel={Epoch},
ylabel={Loss/Accuracy},
title={Training Progress},
legend pos=outer north east,
grid=major,
ymin=0, ymax=1
]
% Training loss
\addplot[blue, thick, mark=*] coordinates {
(1,0.8) (2,0.6) (3,0.45) (4,0.35) (5,0.28) (6,0.22) (7,0.18) (8,0.15) (9,0.13) (10,0.12)
};
\addlegendentry{Train Loss}
% Validation loss
\addplot[red, thick, mark=square*] coordinates {
(1,0.85) (2,0.65) (3,0.50) (4,0.40) (5,0.33) (6,0.28) (7,0.25) (8,0.23) (9,0.22) (10,0.21)
};
\addlegendentry{Val Loss}
% Training accuracy
\addplot[green, thick, mark=triangle*] coordinates {
(1,0.6) (2,0.7) (3,0.78) (4,0.83) (5,0.87) (6,0.90) (7,0.92) (8,0.94) (9,0.95) (10,0.96)
};
\addlegendentry{Train Accuracy}
\end{axis}
\end{tikzpicture}
\end{document}
์ฐ์ต ๋ฌธ์ ¶
์ฐ์ต ๋ฌธ์ 1: ํจ์ ๋น๊ต¶
์ธ ๊ฐ์ง ์ํ ํจ์๋ฅผ ๋น๊ตํ๋ PGFPlots ๊ทธ๋ํ ๋ง๋ค๊ธฐ: - $f(x) = x^2$ - $g(x) = 2^x$ - $h(x) = \log(x)$ ์ ์์ญ $[0.1, 5]$, ๋ค๋ฅธ ์์๊ณผ ์คํ์ผ ์ฌ์ฉ, ๋ฒ๋ก ํฌํจ.
์ฐ์ต ๋ฌธ์ 2: ๋ฐ์ดํฐ๊ฐ ์๋ ๋ง๋ ์ฐจํธ¶
ํ๋งค ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ฃผ๋ ๋ง๋ ์ฐจํธ ๋ง๋ค๊ธฐ: - ์ต์ 6๊ฐ ์นดํ ๊ณ ๋ฆฌ - ๋ง๋ ์์ ํ์๋ ๊ฐ - ๋ง๋์ ์ฌ์ฉ์ ์ ์ ์์ - ์ ์ ํ ์ถ ๋ ์ด๋ธ ๋ฐ ์ ๋ชฉ
์ฐ์ต ๋ฌธ์ 3: 3D ํ๋ฉด ํ๋กฏ¶
๋ค์์ ํฌํจํ๋ ํจ์ $z = \sin(x) \cos(y)$์ 3D ํ๋ฉด ํ๋กฏ ๋ง๋ค๊ธฐ: - ์ ์ ํ ์ ์์ญ - ์์ ๋งต - ์์ ๋ง๋ - ์ถ ๋ ์ด๋ธ
์ฐ์ต ๋ฌธ์ 4: Foreach ๊ฒฉ์ ํจํด¶
\foreach๋ฅผ ์ฌ์ฉํ์ฌ ๋ง๋ค๊ธฐ:
- ์ฒด์ปค๋ณด๋ ํจํด (8ร8 ๊ฒฉ์)
- ๊ต๋๋ก ๋ํ๋๋ ์์ (๊ฒ์์๊ณผ ํฐ์)
- ํํธ: ๋ชจ๋๋ก ์ฐ์ฐ ์ฌ์ฉ
์ฐ์ต ๋ฌธ์ 5: ์ด์ง ํธ๋ฆฌ(Binary Tree)¶
๋ค์์ ํฌํจํ๋ ์์ ํ ์ด์ง ํธ๋ฆฌ ๊ทธ๋ฆฌ๊ธฐ: - 3 ๋ ๋ฒจ (์ด 7๊ฐ ๋ ธ๋) - 1-7์ ์ซ์๊ฐ ์๋ ์ํ ๋ ธ๋ - ๋ ๋ฒจ ๊ฐ ์ ์ ํ ๊ฐ๊ฒฉ - ๋ค๋ฅธ ๋ ๋ฒจ์ ๋ํ ๋ค๋ฅธ ์์
์ฐ์ต ๋ฌธ์ 6: ์ฅ์๋ ๋ค์ด์ด๊ทธ๋จ¶
๋ค์์ ๋ณด์ฌ์ฃผ๋ ๋ค์ด์ด๊ทธ๋จ ๋ง๋ค๊ธฐ: - ๋ณด๋ฅผ ๋ํ๋ด๋ ์ง์ฌ๊ฐํ - ์น์๋ฅผ ๋ ์ด๋ธ ์ง์ ํ๋ brace ์ฅ์ - ์คํ๋ง์ ๋ํ๋ด๋ snake ์ฅ์ - ํ์ดํ๋ก ํ์๋ ํ
์ฐ์ต ๋ฌธ์ 7: ์ ๊ฒฝ๋ง¶
๋ค์์ ํฌํจํ๋ ์ ๊ฒฝ๋ง ๋ค์ด์ด๊ทธ๋จ ์ค๊ณ: - 3๊ฐ์ ์ ๋ ฅ ๋ด๋ฐ - 2๊ฐ์ ์๋์ธต (๊ฐ 4๊ฐ ๋ด๋ฐ) - 2๊ฐ์ ์ถ๋ ฅ ๋ด๋ฐ - ๊ทธ๋ ค์ง ๋ชจ๋ ์ฐ๊ฒฐ - ๋ ์ด์ด ๋ ์ด๋ธ
์ฐ์ต ๋ฌธ์ 8: ์ํ ๊ธฐ๊ณ¶
๋ค์์ ํฌํจํ๋ ์ ํ ์ํ ์คํ ๋งํค ๋ง๋ค๊ธฐ: - ์ต์ 4๊ฐ ์ํ - ์ด๊ธฐ ์ํ ํ์ - ์ต์ ํ๋์ ์๋ฝ ์ํ - ์ฌ๋ฌ ์ ํ (์๊ธฐ ๋ฃจํ ํฌํจ) - ์ ํ ๋ ์ด๋ธ
์ฐ์ต ๋ฌธ์ 9: ๋ค์ค ํจ๋ ํ๋กฏ¶
2๊ฐ์ ๋๋ํ ํ๋กฏ์ด ์๋ ๊ทธ๋ฆผ ๋ง๋ค๊ธฐ: - ์ผ์ชฝ: ์ค์ฐจ ๋ง๋๊ฐ ์๋ ์ฐ์ ๋ - ์ค๋ฅธ์ชฝ: ์ ๋ขฐ ๊ตฌ๊ฐ์ด ์๋ ์ ํ๋กฏ (fill between ์ฌ์ฉ) - ๊ณต์ ์ถ ๋ ์ด๋ธ - ๊ฐ๋ณ ์ ๋ชฉ
์ฐ์ต ๋ฌธ์ 10: ์ถํ ๊ทธ๋ฆผ¶
์คํ ๋ฐ์ดํฐ์ ์ถํ ํ์ง ํ๋กฏ ๋ง๋ค๊ธฐ: - ์ฌ๋ฌ ์๋ฆฌ์ฆ๊ฐ ์๋ ์ ํ๋กฏ - ๋ฐ์ดํฐ ํฌ์ธํธ์ ์ค์ฐจ ๋ง๋ - ์๋ฏธ ์๋ ๋ ์ด๋ธ์ด ์๋ ๋ฒ๋ก - ๊ฒฉ์ (์ฃผ์ ๋ฐ ๋ณด์กฐ) - ์ ์ ํ ๊ธ๊ผด ํฌ๊ธฐ - ์ ๋ฌธ์ ์ธ ์์ ๊ตฌ์ฑํ - ์ ๋์ ์ ํฉํ ๋ด๋ณด๋ด๊ธฐ ํฌ๊ธฐ (์: 12cm ๋๋น)
์์ฝ¶
์ด ๋ ์จ์์ ๋ค์์ ๋ฐฐ์ ์ต๋๋ค:
- PGFPlots ๊ธฐ์ด: ์ถ ํ๊ฒฝ ์์ฑ, ํจ์ ๋ฐ ๋ฐ์ดํฐ ํ๋กํ
- ํจ์ ํ๋กฏ: ์ ์์ญ, ์ํ, ์ฌ๋ฌ ํจ์, ์ํ ํํ์
- ๋ฐ์ดํฐ ํ๋กฏ: ์ขํ, ํ ์ด๋ธ, ์ธ๋ถ ๋ฐ์ดํฐ ํ์ผ
- ํ๋กฏ ์คํ์ผ: ์ , ์ฐ์ ๋, ๋ง๋, ์์ญ, ํ์คํ ๊ทธ๋จ ํ๋กฏ
- ์ฌ๋ฌ ์ถ: ๋ฒ๋ก, ๋ ์ด๋ธ, ์ ๋ชฉ, ๊ฒฉ์ ์ปค์คํฐ๋ง์ด์ง
- 3D ํ๋กฏ: ํ๋ฉด ํ๋กฏ, ๋ฉ์ ํ๋กฏ, ๋งค๊ฐ๋ณ์ 3D ๊ณก์
- ์ค์ฐจ ๋ง๋: ํ๋กฏ์ ๋ถํ์ค์ฑ ์๊ฐํ ์ถ๊ฐ
- Foreach ๋ฃจํ: ๊ทธ๋ฆฌ๊ธฐ ๋ช ๋ น์ ํจ์จ์ ์ผ๋ก ๋ฐ๋ณต
- ํธ๋ฆฌ: ์๋ ๋ ์ด์์์ผ๋ก ๊ณ์ธต ๊ตฌ์กฐ ์์ฑ
- ๊ทธ๋ํ: graphs ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๋ณต์กํ ๊ทธ๋ํ ๊ตฌ์กฐ
- ์ฅ์: snake, brace, zigzag์ ๊ฐ์ ์๊ฐ์ ํจ๊ณผ ์ถ๊ฐ
- ํจํด: ๋ฐ๋ณต ํจํด์ผ๋ก ์์ญ ์ฑ์ฐ๊ธฐ
- ๋ ์ด์ด: ๋ณต์กํ ๊ทธ๋ํฝ์ ๊ทธ๋ฆฌ๊ธฐ ์์ ์ ์ด
- Spy: ์ธ๋ถ ๋ณด๊ธฐ๋ฅผ ์ํ ๋๋ณด๊ธฐ ํจ๊ณผ
- External: ๋ ๋น ๋ฅธ ๋น๋๋ฅผ ์ํด ์ปดํ์ผ๋ ๊ทธ๋ํฝ ์บ์ฑ
- ๋ณต์กํ ์์ : ์ ๊ฒฝ๋ง, ์ํ ๊ธฐ๊ณ, ์ถํ ํ๋กฏ
์ด๋ฌํ ๊ณ ๊ธ TikZ ๋ฐ PGFPlots ๊ธฐ๋ฒ์ ์ฌ์ฉํ๋ฉด ์ ๋ฌธ์ ์ด๊ณ ํ์ ์ ์ถํ ํ์ค์ ์ถฉ์กฑํ๋ ์ ๊ตํ ๋ค์ด์ด๊ทธ๋จ, ๋ฐ์ดํฐ ์๊ฐํ ๋ฐ ๊ธฐ์ ์ผ๋ฌ์คํธ๋ ์ด์ ์ ๋ง๋ค ์ ์์ต๋๋ค. ์ด๋ฌํ ๊ธฐ์ ์ ๊ณผํ ๋ ผ๋ฌธ, ๊ธฐ์ ๋ณด๊ณ ์ ๋ฐ ํ๋ ์ ํ ์ด์ ์์ ๊ณ ํ์ง ๊ทธ๋ฆผ์ ๋ง๋๋ ๋ฐ ํ์์ ์ ๋๋ค.
์ด์ : 10_TikZ_Basics.md ๋ค์: 12_Beamer_Presentations.md