具有选择性显示的极坐标图

具有选择性显示的极坐标图

我现在遇到了极坐标图的问题。

原代码如下:

\documentclass[10pt,border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.12}    

\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[
   xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
   xtick={0,30,...,330},
   ytick={-40,-30,...,0},
   ymin=-40, ymax=0,
   y coord trafo/.code=\pgfmathparse{#1+40},
   rotate=-90,
   y coord inv trafo/.code=\pgfmathparse{#1-40},
   x dir=reverse,
   xticklabels={$0^\circ$, $30^\circ$, $60^\circ$, $90^\circ$, $120^\circ$, $150^\circ$, $180^\circ$, $-150^\circ$, $-120^\circ$, $-90^\circ$, $-60^\circ$, $-30^\circ$},
   %xmin=-90, xmax=90,
   xticklabel style={anchor=-\tick-90},
   yticklabel style={anchor=east, xshift=-4.75cm},
   ylabel={\shortstack{Directivity\\(dB)}},
   %ylabel={dB},
   ylabel style={xshift=-8.5cm, yshift=-0.4cm},
   xlabel ={$\theta (^\circ)$},
   xlabel style={xshift=0cm, yshift=-5.6cm},
   y axis line style={yshift=-4.75cm},
   ytick style={yshift=-4.75cm},
   legend style={nodes={scale=0.7, transform shape},at={(1,1)},anchor=south west}
]

\legend{Simulated at 28 GHZ,27 GHz, 28 GHz, 29 GHz, 30 GHz, 31GHz}


\addplot [no markers, thick, red] table [x = theta, y=E] {coaxial.txt};

\addplot [dashed,mark=*, thick, purple, mark options={scale=0.5}] table [x = theta, y=E] {EPlane27GHZ.txt};

\addplot [dashed,mark=*, thick, blue, mark options={scale=0.5}] table [x = theta, y=E] {EPlane28GHZ.txt};

\addplot [dashed,mark=*, thick, green,mark options={scale=0.5}] table [x = theta, y=E] {EPlane29GHZ.txt};

%\addplot [dashed, mark=* , thick, orange, mark options={scale=0.5}] table [x = theta, y=E] {EPlane30GHZ.txt};

%\addplot [dashed, mark=* , thick, purple, mark options={scale=0.5}] table [x = theta, y=E] {EPlane31GHZ.txt};

\end{polaraxis}
\end{tikzpicture}
\end{document}

效果如下:

在此处输入图片描述

我想要实现的目标是:

在此处输入图片描述

只保留上部,下部应该消失。我应该如何调整我的代码?

谢谢!

答案1

我可能会做一些不同的事情:

  • 为了只得到一半的地块,我会限制Xxmin使用和将轴设置为 0 到 180 度之间的值xmax(负值似乎在极坐标图中不起作用)。我还会明确说明刻度标签,以便它们从左下角的“-90”开始。
  • 完成此操作后,我们还需要将图旋转 90 度。这可以通过在数据中创建一个新列(使用pgfplotstable也加载的包pgfplots)来实现,该列包含列中的值theta加上 90 度。
  • 至于您想要在图的左侧显示的轴,我可能会手动绘制它,而不是旋转并将所有内容移动到正确的位置,这可能有点乏味。
  • 为了使手动绘制的轴显示在绘图区域之外,但仍将绘图剪切到轴上,您可以添加clip mode=individual选项axis

完整的 MWE(我把绘图数据取自你的其它问题):

\documentclass[border=10pt]{standalone}
\usepackage{pgfplotstable}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.18}

\pgfplotstableset{
    create on use/X/.style={
        create col/expr={\thisrow{theta}+90}
    }
}

\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[
    clip mode=individual,
    xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
    xtick={0,30,...,180},
    ytick={-40,-30,...,0},
    ymin=-40, ymax=0,
    xmin=0, xmax=180,
    y coord trafo/.code=\pgfmathparse{#1+40},
    y coord inv trafo/.code=\pgfmathparse{#1-40},
    x dir=reverse,
    xticklabels={$-90^\circ$, $-60^\circ$, $-30^\circ$, $0^\circ$, $30^\circ$, $60^\circ$, $90^\circ$},
    xticklabel style={anchor=-\tick},
    yticklabels={},
    y tick style={draw=none},
    xlabel={$\theta (^\circ)$},
    every axis x label/.style={
        at={(ticklabel cs:0)},
    },
    legend style={nodes={scale=0.7, transform shape}, at={(1,1)}, anchor=south west}
]

\legend{Simulated at 28 GHZ, 27 GHz, 28 GHz, 29 GHz, 30 GHz, 31GHz}

\addplot[no markers, thick, red] 
    table[x=X, y=E] {test.txt};

\draw (-5cm,0cm) -- (-5cm,0cm |- 90,0);
\foreach \y in {-40,-30,...,0} {
    \edef\temp{
        \noexpand\draw[very thin, gray] (-5cm,0cm |- 90,\y) -- ++(-0.15cm,0cm)
            node[black, left] {$\y$};
    }\temp
}
\node[align=center] at (-7cm,0cm |- 90,-20) {Directivity \\ (dB)};

\end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

无需为数据创建额外列的替代解决方案:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplotstable}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[
    clip mode=individual,
    clip bounding box=default tikz,
    xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
    xtick={-90,-60,...,90},
    ytick={-40,-30,...,0},
    ymin=-40, ymax=0,
    xmin=-90, xmax=90,
    rotate=-90,
    y coord trafo/.code=\pgfmathparse{#1+40},
    y coord inv trafo/.code=\pgfmathparse{#1-40},
    x dir=reverse,
    xticklabels={$-90^\circ$, $-60^\circ$, $-30^\circ$, $0^\circ$, $30^\circ$, $60^\circ$, $90^\circ$},
    xticklabel style={anchor=-\tick-90},
    yticklabels={},
    y tick style={draw=none},
    xlabel={$\theta (^\circ)$},
    every axis x label/.style={
        at={(ticklabel cs:0)},
    },
    legend style={nodes={scale=0.7, transform shape}, at={(0,1)}, anchor=south west}
]

\legend{Simulated at 28 GHZ, 27 GHz, 28 GHz, 29 GHz, 30 GHz, 31GHz}

\addplot[no markers, thick, red] table[x=theta, y=E] {test.txt};

\begin{scope}[rotate=90]
\draw (-5cm,0cm) -- (-5cm,0cm |- 90,0);
\foreach \y in {-40,-30,...,0} {
    \edef\temp{
        \noexpand\draw[very thin, gray] (-5cm,0cm |- 90,\y) -- ++(-0.15cm,0cm)
            node[black, left] {$\y$};
    }\temp
}
\node[align=center] at (-7cm,0cm |- 90,-20) {Directivity \\ (dB)};
\end{scope}

\end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容