6

I want to use \addplot twice and I want to filter the x values in one of them. However, x filter/.code={...} goes into the axis options and thus is applied to all \addplots. How can I select a specific \addplot?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[x filter/.code={\pgfmathadd{#1}{0.5}}]
\addplot coordinates { %use `x filter' only here,
(4,0)
(6,1)
};
\addplot coordinates {%but not here !!
(6.5,0)
(4.4,1)
};
\end{axis}
\end{tikzpicture}
\end{document}
5

You can add the x filter to the addplot options.

For reference: As mentioned in your other question, compilation error with `legend entries={...}` and `y filter/.code={...}`, errors can occur when #1 is used here. Workaround suggested in manual is to use \pgfmathresult instead of #1.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [x filter/.code={\pgfmathadd{#1}{0.5}},blue,mark=*] coordinates { %use `x filter' only here,
(4,0)
(6,1)
};
\addplot  coordinates {%but not here !!
(6.5,0)
(4.4,1)
};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

0

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.