chrisphan.com

Plotting with TikZ, Part I: Why?

An analog clock reading 8:582019-05-01 / 2019-W18-3T08:58:30-05:00 / 0x5cc9a606

Categories: TikZ ist kein Zeichenprogramm, indeed, LaTeX, math

This is the first part of a three-part series of posts on generating plots of graphs with TikZ. Last year, I left my position as a mathematics professor, after teaching mathematics at the college level for 15 years (nine years as a faculty member, and six years as a graduate teaching fellow). In that time, I picked up a lot of tricks using LaTeX to produce teaching materials (handouts and slides). I decided it might be good to record some of that knowledge somewhere, and my blog seems like a natural place.

Outline

I'm planning a three-part series:

What is TikZ?

TikZ is a powerful LaTeX package for producing illustrations. TikZ is short for "TikZ ist kein Zeichenprogramm", which I understand means "TikZ is not a drawing program" in German. (Technically, TikZ comes bundled on top of another package called PGF, and the actual package is PGF/TikZ. I will refer to the package as just "TikZ" in this series of posts.) Unlike traditional illustration software such as Illustrator, in which the user would use a graphical interface create graphics, one creates graphics in TikZ with drawing commands. Here is an example of a short LaTeX document in which TikZ is used to produce a few shapes:

LaTeX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
\documentclass[border=0.25cm]{standalone}

\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    % Square
    \draw[dashed, blue] (0, 0) -- (0, 2)
    -- (2, 2) -- (2, 0) -- cycle;

    % Triangle
    \draw[thick, green, fill=green] (3, 0)
      -- (4, 2) -- (5, 0) -- cycle;

    % Circle
    \draw[thick, red, fill=purple]
      (6, 0) circle (0.5 cm);

    % Arrow
    \draw[->, thick, brown] (0, -1) -- (6.5, -1);

  \end{tikzpicture}
\end{document}

And here is the result:

a square made out of dashed, blue lines; a green filled triangle; a red circle filled with purple; and a long brown arrow

Here's an example of an illustration I created for a calculus exam, using TikZ:

a isometric diagram of a trapezoidal prism water trough, partially filled with water, with dimensions labelled

You can find a number of beautiful TikZ examples on TeXample.net and on the TeX StackExchange under the "TikZ-PGF" tag.

Why use TikZ to make plots?

To be frank, creating illustrations in TikZ can sometimes be time-consuming. For example, to create the water trough illustration above, it would not be unreasonable to prefer using illustration software or drawing the diagram freehand. For plots, you can make great illustration using SageMath, Desmos, or Matplotlib. But I still sometimes prefer TikZ to create plots.

In the next post, I will explain how to create a plot like the one above.