3

I added a global option using every axis/.append style={before end axis/.code={}} to draw a box around every plot. However, I have some graphs where I would like to suppress the execution of this code. How can I do this?

Here is my MWE:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{backgrounds}

\usepackage{pgfplots}

% Make a red box around every plot (because its beautiful)
\pgfplotsset{every axis/.append style={before end axis/.code={
\begin{scope}[on background layer]
\draw[thin,red,solid] ({rel axis cs:0,0}) |- ({rel axis
cs:1,1}) |- cycle;
\end{scope}}}}



\begin{document}

\begin{tikzpicture}
% Already tried to use this, to no avail:
% [every axis/.append style={before end
% axis/.code={}}] 

% Don't want to have box around this graph
\begin{axis}[axis x line=none,%
axis y line=none]
\addplot {x^2};
\end{axis}

\end{tikzpicture}


\end{document}
5

Just say before end axis/.code={} in the axis where you want to suppress the box.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{backgrounds}

\usepackage{pgfplots}

% Make a red box around every plot (because its beautiful)
\pgfplotsset{every axis/.append style={before end axis/.code={
      \begin{scope}[on background layer]
        \draw[thin,red,solid] ({rel axis cs:0,0}) |- ({rel axis
          cs:1,1}) |- cycle;
      \end{scope}}}}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[axis x line=none,%
    axis y line=none]
    \addplot {x^2};
  \end{axis}
\end{tikzpicture}

% Don't want to have box around this graph
\begin{tikzpicture}
  \begin{axis}[axis x line=none,%
    axis y line=none,before end axis/.code={}]
    \addplot {x^2};
  \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
  \begin{axis}[axis x line=none,%
    axis y line=none]
    \addplot {x^2};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

1
  • okay, so the trick is to use it in the axis-environment options, and not as append style. Thanks! Aug 14 '17 at 8:29

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.