4

I want to plot only some values of an external tex value table, for example from the 3rd value to the 6th value. I could manually comment the non-wanted values but the table may often change and I don't want to comment each time the table changes. In addition, I need the complete table for other plots. Here an example of code:

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

enter image description here

Thank you very much in advance.

  • Thank you, I also need this option, "every n-th value" so I bookmark this thread, but I want also the starting and ending point, but I have the feeling that I saw this option by going from link to link. => \addplot table [x expr=\coordindex+1,y index=0,skip coords between index={101}{2700}]{datafile.txt} I will try this! – Willi Aug 4 '14 at 21:15
4

You can set a xfilter

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

Note that the first value has the \coordindex 0. So the 3rd to the 6th value will be plotted:

enter image description here

Code:

\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

You can also use skip coords between index={<begin>}{<end>}, key. From manual,

A style which appends an x filter which discards selected coordinates. The selection is done by index where indexing starts with 0, see \coordindex. Every coordinate with index ≤ i < will be skipped.

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

enter image description here

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.