๊ณ ๊ธ‰ 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

to navigate between lessons