Graphics, Figures & TablesPolar Plots in Tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Kavar0
Posts: 1
Joined: Tue May 13, 2014 11:55 am

Polar Plots in Tikz

Post by Kavar0 »

I found this beautiful example for a polar plot by Zoran Nikolic, but I'm having trouble plotting polar plots on top of it.

Code: Select all

%POLAR COORDINATES
%The print template for A4 paper (portrait)
%Author: Zoran Nikolic
\documentclass[12pt]{article}
\usepackage[margin=0.5in,paper=a4paper]{geometry} %Shrinking margins to 0.5in
\usepackage[x11names]{xcolor}                     %Additional colors
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title:  Polar coordinates template

\end{comment}
\usepackage{euler}                                %Nicer numbers
\usepackage{tikz}
%Note about the colors: 
%  The color of the "ray" lines should not be
%  black or gray as on some printers, significant
%  aliasing distorsion becomes visible.

\begin{document}
\thispagestyle{empty} %Please, no page numbers or similar

\begin{center}
  \begin{tikzpicture}
    %Circles 
    \foreach \r in {1, 2,...,7}
      \draw[SteelBlue3, thick] (0,0) circle (\r);    
    \foreach \r in {0.5, 1.5,...,7}
      \draw[Azure4, thin] (0,0) circle (\r);
    %1° Rays
    \foreach \a in {0, 1,...,359}
      \draw[Azure4] (\a:7.7) -- (\a:8);
    %5° Rays
    \foreach \a in {0, 5,...,359}
      \draw[Azure4] (\a:7.5) -- (\a:8);      
    %15° Rays
    \foreach \a in {0, 15,...,359}
      \draw[thick,Azure4] (\a:1) -- (\a:8); 
    %30° Rays
    \foreach \a in {0, 30,...,359}
      \draw[thick,Azure4] (0, 0) -- (\a:8);
    %Radius labels (background filled white)
    \foreach \r in {1, 2,...,7}
      \draw (\r,0) node[inner sep=1pt,below=3pt,rectangle,fill=white] {$\r$};
    %Main rays
    \foreach \a in {0, 90,...,359}
      \draw[very thick] (0, 0) -- (\a:8);
    %Angle labels  
    \foreach \a in {0, 15,...,359}
      \draw (\a: 8.5) node {$\a^\circ$};
    %Central point
    \draw[fill=red] (0,0) circle(0.7mm);

  \end{tikzpicture}
\end{center}

\end{document}
How do I plot polar plots on top of this diagram?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Polar Plots in Tikz

Post by Stefan Kottwitz »

Hi Kavar0,

welcome to the forum!

I suggest using pgfplots for polar plots, it provides a library for it an can be customized. Have a look at this polar plot or the whole pgfplots gallery, especially if you would like to do other plots as well.

TikZ provides also some native plotting features. I just prefer the customizable capable pgfplots package, which builds on top of TikZ/pgf.

However, you can mix it. Here, I add a pgfplots plot (polar axis plot) to your starting example. I set the pgfplot axis to hidden and adjust the origin, to match the TikZ picture. Check that the scaling matches between pgfplots and TikZ, x and y value.

Code: Select all

%POLAR COORDINATES
%The print template for A4 paper (portrait)
%Author: Zoran Nikolic
\documentclass[12pt]{article}
\usepackage[margin=0.5in,paper=a4paper]{geometry} %Shrinking margins to 0.5in
\usepackage[x11names]{xcolor}                     %Additional colors
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title:  Polar coordinates template

\end{comment}
\usepackage{euler}                                %Nicer numbers
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
%Note about the colors: 
%  The color of the "ray" lines should not be
%  black or gray as on some printers, significant
%  aliasing distorsion becomes visible.

\begin{document}
\thispagestyle{empty} %Please, no page numbers or similar

\begin{center}
  \begin{tikzpicture}
    %Circles 
    \foreach \r in {1, 2,...,7}
      \draw[SteelBlue3, thick] (0,0) circle (\r);    
    \foreach \r in {0.5, 1.5,...,7}
      \draw[Azure4, thin] (0,0) circle (\r);
    %1° Rays
    \foreach \a in {0, 1,...,359}
      \draw[Azure4] (\a:7.7) -- (\a:8);
    %5° Rays
    \foreach \a in {0, 5,...,359}
      \draw[Azure4] (\a:7.5) -- (\a:8);      
    %15° Rays
    \foreach \a in {0, 15,...,359}
      \draw[thick,Azure4] (\a:1) -- (\a:8); 
    %30° Rays
    \foreach \a in {0, 30,...,359}
      \draw[thick,Azure4] (0, 0) -- (\a:8);
    %Radius labels (background filled white)
    \foreach \r in {1, 2,...,7}
      \draw (\r,0) node[inner sep=1pt,below=3pt,rectangle,fill=white] {$\r$};
    %Main rays
    \foreach \a in {0, 90,...,359}
      \draw[very thick] (0, 0) -- (\a:8);
    %Angle labels  
    \foreach \a in {0, 15,...,359}
      \draw (\a: 8.5) node {$\a^\circ$};
    %Central point
    \draw[fill=red] (0,0) circle(0.7mm);
    % Now the additional plot:
    \begin{polaraxis}[hide axis,anchor=origin,disabledatascaling,at={(0pt,0pt)},x=1cm,y=1cm]
    \addplot+[mark=none,domain=0:720,samples=600,thick] 
        {30*sin(2*x)*cos(2*x)}; 
    \end{polaraxis}
  \end{tikzpicture}
\end{center}

\end{document}
polar-plot.png
polar-plot.png (114.93 KiB) Viewed 8077 times
Stefan
LaTeX.org admin
Post Reply