6

I'd like to do a logarithmic polar plot like the one in Wikipedia Polar Plot.

I've come up with the following PGF Plot so far:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots} 
\usepgfplotslibrary{polar}

\begin{document}
\pgfplotsset{mypolarplot/.style={%
      domain=0:360, % plot full cycle
      samples=180, % number of samples; can be locally adjusted
      grid=both, % display major and minor grids
      major grid style={black}, 
      minor x tick num=3, % 3 minor x ticks between majors
      minor y tick num=1, % 1 minor y tick between majors
      xtick={0,45,...,360}, % set xticks (degrees)
      yticklabel style={anchor=north east}, % move label position
      xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
      every axis plot/.style={ultra thick},
}}
\begin{tikzpicture}
\begin{polaraxis}[mypolarplot]
\addplot[blue]{abs(cos(x))}; % linear scale
%\addplot[blue]{abs(20*log10(abs(cos(x)))};  % log scale      
\end{polaraxis}
\end{tikzpicture}
\end{document}

But I can't get the scaling of the polar plot right, I'd like to have a range of say -40 ... 0 dB for the radius. Any ideas?

  • 2
    Did you try using coordinate transformations (like e.g. here)? – user121799 Nov 7 '18 at 13:47
  • No, yet another thing I didn't know about TikZ - exactly what I need! If you answer the question, I can give give you credit. – Chipmuenk Nov 7 '18 at 16:30
2

With the information in "Polar plot using pgfplots/tikz" it was easy to answer my own question. The trick was using y coord trafo/.code=\pgfmathparse{#1+40} to transform values so that -40 (dB) is represented by a radius of 0 and 0 dB by a radius of 40.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots} 
\usepgfplotslibrary{polar}

\begin{document}
\pgfplotsset{mypolarplot/.style={%
    domain=0:360, % plot full cycle
    samples=180, % number of samples; can be locally adjusted
    grid=both, % display major and minor grids
    major grid style={black}, 
    minor x tick num=3, % 3 minor x ticks between majors
    minor y tick num=1, % 1 minor y tick between majors
    xtick={0,45,...,360}, % set xticks (degrees)
    yticklabel style={anchor=north east}, % move label position
    xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
    every axis plot/.style={ultra thick},
    ymin=-30, ymax=0
 }}
\begin{tikzpicture}
\begin{polaraxis}[mypolarplot,
    % shift y-coordinates by +40 (-40 for reverse direction)
    y coord trafo/.code=\pgfmathparse{#1+40},
    y coord inv trafo/.code=\pgfmathparse{#1-40}]
\addplot[blue]{20*log10(abs(cos(x)))};        
\end{polaraxis}
\end{tikzpicture}
\end{document}

Log Polar Plot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.