使用 TikZ/pgfplot 进行对数极坐标图

使用 TikZ/pgfplot 进行对数极坐标图

我想做一个像维基百科 极坐标图

到目前为止我已经提出了以下 PGF 图:

\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}

但我无法正确缩放极坐标图,我希望半径的范围为 -40 ... 0 dB。有什么想法吗?

答案1

有了“使用 pgfplots/tikz 绘制极坐标图”回答我自己的问题很容易。诀窍是使用y coord trafo/.code=\pgfmathparse{#1+40}转换值,以便 -40 (dB) 由半径 0 表示,而 0 dB 由半径 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}

对数极坐标图

相关内容