Blog 1

Random Talk on Random Thoughts

Plot Polar Coordinates Graphs

| Comments |

Googling “tikz tutorial”, one can find several useful PDF documents which are easy to follow, such as the first two results.

  1. PGF/TikZ - Graphics for $\rm \LaTeX$ —A tutorial by Meik Hellmund
  2. A very minimal introduction to TikZ by Jacques Crémer

The second PDF document covers plotting graphs in rectangular coordinates. How about polar coordinates?

It’s easy to find a solution online, but understanding the code and adapting them according to your needs are much harder. One has to make use of “cs”, which stands for “coordinate system”. If one is too lazy to read more webpages, then one may use the code below.

When I drew figures with TikZ a recent post on limits of composite functions on $\R^n$, I found a way to construct random region with TikZ in a $\rm \TeX$–$\rm \LaTeX$ Stack Exchange question.1 This inspired me to come up with the following graph.

Output

polar plot

Source code

The $\rm \LaTeX$ source code for the above graph (TikZPolar.tex) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  % drawing grid lines
  \foreach \r in {1,...,6} {\draw (0,0) circle (\r);}
  \draw (-6.5,0) -- (6.5,0);
  \foreach \theta in {15,30,...,165} {\draw (\theta:6.5) -- (\theta+180:6.5);}
  % labelling them
  \foreach \r in {2,4,6} {\node[below left] (lbl\r) at (\r,0) {\r};}
  \foreach \t in {0,30,...,330} {
    \node [draw,fill=white] (lbl\t) at (\t:7) {$\theta = \t^\circ$};
  }
  % graph of $r = 5 - \sin(3\theta)$
  \draw[red,ultra thick,smooth cycle,samples=200,domain=0:359]
  plot (\x:{5-sin(3*\x)});
  \node at (270:8) {The graph of $r = 5 - \sin(3\theta)$};
\end{tikzpicture}
\end{document}
  • I got the idea of for loop in TikZ from TikZ and PGF Manual.
  • I learnt the syntax for plotting functions from the PDF in item (2).

  1. Refer to TikZ: Arbitrary shapes and filling? for details. 

Comments