如何仅绘制表格的某些值?

如何仅绘制表格的某些值?

我想仅绘制外部 tex 值表中的某些值,例如从第 3 个值到第 6 个值。我可以手动注释不需要的值,但表格可能经常更改,我不想每次表格更改时都进行注释。此外,我需要完整的表格用于其他绘图。下面是代码示例:

\centering
\begin{tikzpicture}
\begin{polaraxis}[
    visualization depends on=x \as \pgfplotspointx,
    nodes near coords,
    every node near coord/.style={
        rotate=\pgfplotspointx,
        append after command={
        node [
            anchor=south,
            rotate=\pgfplotspointx,
            shift={(axis direction cs:0,(12.75-\pgfplotspointmeta))}
        ] {$\pgfmathprintnumber{\pgfplotspointx}^\circ$}
    }
},
width=4.2\textwidth,
xmin=-1,xmax=45.01, ymin=12, ymax=15,
title=Displacement 12N,
grid=both,
minor x tick num={4}, 
minor y tick num={1},
]
\addplot+[polar comb ,data cs=cart, mark size=1, mark=asterisk] table {
13.8893888888889    0
13.8875152609215    0.256057893044211
13.8818942709919    0.512013162090311
13.8725256030249    0.767763280177719
13.8594087369111    1.02320591422122
13.8425429585071    1.27823902144993
13.8219273735841    1.53276094524909
13.7975609256787    1.78667051020809
13.7694424177793    2.03986711617976
13.7375705377745    2.29225083115874
13.7019438875704    2.54372248278928
13.6625610157771    2.79418374831654
13.6194204538470    3.04353724279891
13.5725207555396    3.29168660540349
13.5218605395737    3.53853658361110
13.4674385353184    3.78399311516262
13.4092536313646    4.02796340758379
};
\end{polaraxis}
\end{tikzpicture}

在此处输入图片描述

提前非常感谢您。

答案1

您可以设置xfilter

x filter/.code={%
  \ifnum\coordindex<2\def\pgfmathresult{}\fi%
  \ifnum\coordindex>5\def\pgfmathresult{}\fi%
  }%

请注意,第一个值为\coordindex0。因此,将绘制第 3 到第 6 个值:

在此处输入图片描述

代码:

\documentclass{scrartcl}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.10}
\begin{document}
\centering
\begin{tikzpicture}
\begin{polaraxis}[
    visualization depends on=x \as \pgfplotspointx,
    nodes near coords,
    every node near coord/.style={
        rotate=\pgfplotspointx,
        append after command={
        node [
            anchor=south,
            rotate=\pgfplotspointx,
            shift={(axis direction cs:0,(12.75-\pgfplotspointmeta))}
        ] {$\pgfmathprintnumber{\pgfplotspointx}^\circ$}
    }
},
width=4.2\textwidth,
xmin=-1,xmax=45.01, ymin=12, ymax=15,
title=Displacement 12N,
grid=both,
minor x tick num={4}, 
minor y tick num={1},
x filter/.code={%
  \ifnum\coordindex<2\def\pgfmathresult{}\fi%
  \ifnum\coordindex>5\def\pgfmathresult{}\fi%
  }%
]
\addplot+[polar comb ,data cs=cart, mark size=1, mark=asterisk] table {
13.8893888888889    0
13.8875152609215    0.256057893044211
13.8818942709919    0.512013162090311
13.8725256030249    0.767763280177719
13.8594087369111    1.02320591422122
13.8425429585071    1.27823902144993
13.8219273735841    1.53276094524909
13.7975609256787    1.78667051020809
13.7694424177793    2.03986711617976
13.7375705377745    2.29225083115874
13.7019438875704    2.54372248278928
13.6625610157771    2.79418374831654
13.6194204538470    3.04353724279891
13.5725207555396    3.29168660540349
13.5218605395737    3.53853658361110
13.4674385353184    3.78399311516262
13.4092536313646    4.02796340758379
};
\end{polaraxis}
\end{tikzpicture}
\end{document}

答案2

您也可以使用skip coords between index={<begin>}{<end>},键。从手册中,

附加 x 过滤器的样式,该过滤器会丢弃选定的坐标。选择是通过索引完成的,索引从 0 开始,请参阅 \coordindex。索引 ≤ i < 的每个坐标都将被跳过。

\documentclass{scrartcl}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.10}
\begin{document}
\centering
\begin{tikzpicture}
\begin{polaraxis}[
    visualization depends on=x \as \pgfplotspointx,
    nodes near coords,
    every node near coord/.style={
        rotate=\pgfplotspointx,
        append after command={
        node [
            anchor=south,
            rotate=\pgfplotspointx,
            shift={(axis direction cs:0,(12.75-\pgfplotspointmeta))}
        ] {$\pgfmathprintnumber{\pgfplotspointx}^\circ$}
    }
},
width=4.2\textwidth,
xmin=-1,xmax=45.01, ymin=12, ymax=15,
title=Displacement 12N,
grid=both,
minor x tick num={4},
minor y tick num={1},
skip coords between index={0}{2},      %%% This one and 
skip coords between index={6}{17}      %% This one
]
\addplot+[polar comb ,data cs=cart, mark size=1, mark=asterisk] table {
13.8893888888889    0
13.8875152609215    0.256057893044211
13.8818942709919    0.512013162090311
13.8725256030249    0.767763280177719
13.8594087369111    1.02320591422122
13.8425429585071    1.27823902144993
13.8219273735841    1.53276094524909
13.7975609256787    1.78667051020809
13.7694424177793    2.03986711617976
13.7375705377745    2.29225083115874
13.7019438875704    2.54372248278928
13.6625610157771    2.79418374831654
13.6194204538470    3.04353724279891
13.5725207555396    3.29168660540349
13.5218605395737    3.53853658361110
13.4674385353184    3.78399311516262
13.4092536313646    4.02796340758379
};
\end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容