3

I asked another question and not only did percusse explain the code, but went even farther and wrote my code for me. That is beyond awesome. All I need to do is switch the part of the plot that the every nth point code acts on. I was able to do this in a roundabout way:

\documentclass{standalone}
    \usepackage{pgfplots}

    \makeatletter

    \pgfplotsset{
        my filter/.style args={every#1between#2and#3}{%
            /pgfplots/x filter/.append code={%
                \ifnum\coordindex<#2%
                    \pgfmathsetmacro\temp{int(mod(\coordindex,#1))}%
                    \ifnum0=\temp\relax
                        %pass
                    \else
                        \let\pgfmathresult\pgfutil@empty
                    \fi%
                \else
                    \ifnum\coordindex>#3%
                        \pgfmathsetmacro\temp{int(mod(\coordindex,#1))}%
                        \ifnum0=\temp\relax
                            %pass
                        \else
                            \let\pgfmathresult\pgfutil@empty
                        \fi%
                    \else
                        %pass
                    \fi%
                \fi%
            }
        }
    }
    \makeatother

\begin{document}

\begin{tikzpicture}
    \begin{axis}[my filter=every 50 between 600 and 1050]
        \addplot[samples=1501] {sin(deg(5*x))};
    \end{axis}
\end{tikzpicture}

\end{document}

This has the effect I desire:

smoothMiddle

Unfortunately, the code I hacked is pretty dirty. Not only is the code repeated, but the style args read as if the code does the opposite. Does anybody know what syntax I might use to change every#1between#2and#3 to the opposite? I tried every#1except between#2and#3, every#1!between#2and#3, every#1not between#2and#3, every#1outside#2and#3, every#1out of#2and#3, every#1below#2or above#3 and things of that nature. None of them worked, and for the life of me, I can't find negative style arg keywords in the TikZ manual except for without.

aeroNotAuto
  • 2,390

1 Answers1

4

The style names are something you cook up for yourself. So TikZ won't recognize the words when you try to invert them. The actual name is in the definition so I changed it to something else that you have given in the question.

For the inversion, since we are trying to go in to two nested ifs and the result is doing nothing then the default action outside ifs should be true anyways. Then you can separate the test and the action as follows

\documentclass{standalone}
\usepackage{pgfplots}
\makeatletter
\pgfplotsset{
    my filter/.style args={every#1except#2and#3}{%
        /pgfplots/x filter/.append code={%
            \def\myswitch{1}% Switch is by default on, you can do this with a TeX \if too
            \ifnum\coordindex>#2%Ready to turn off the filter?
            % Yes but are we still in the desired interval?
                \ifnum\coordindex<#3
                \def\myswitch{0}% Turn it off
                \fi%
            \fi%No else
            % Now if the switch is on
            \ifnum1=\myswitch%
                \pgfmathsetmacro\temp{int(mod(\coordindex,#1))}%
                    \ifnum0<\temp
                        \let\pgfmathresult\pgfutil@empty
                    \fi%
            \fi%
        }
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[my filter=every 50 except 600 and 1050]% Note this name matches the definiton
\addplot[samples=1501] {sin(deg(5*x))};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

I've also given a recent answer to multiple argument style stuff in this one

\tikzset key with multiple arguments

in case you need more details. But the TikZ manual is always the most useful.

percusse
  • 157,807