1

When I use pgfplots to draw into a 3D axis, the drawn objects outside the axis are sometimes clipped, although I use clip=false. This only happens when I use the TikZ externalization library and I think this is caused by pdflatex cropping the external pdf to the bounding box. For example,

\documentclass[border=2pt]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\usetikzlibrary{external}
\tikzexternalize

\begin{document}
\begin{tikzpicture}
    \begin{axis}[xmin=-1,xmax=1,
        ymin=-1,ymax=1,
        zmin=0,zmax=1,
        clip=false]
        \draw (0,0,0) circle (3);
    \end{axis}
\end{tikzpicture}
\end{document}

results in the following external pdf: enter image description here

However, I want the whole circle to be shown. So, the question is whether there is a way to automatically adjust the bounding box to include all drawn objects.

  • 1
    When I use your code I get something completely different; a tiny circle at the lower left corner, (rel axis cs: 0,0,0). You might want to update you packages. – John Kormylo Dec 9 '16 at 15:49
  • Thanks for the comment, you require compat=1.11 or higher to get the output shown above. I've amended the code in my original post to make this clear. – winxi Dec 9 '16 at 18:47
  • The good news is that it has nothing to do with pgfplots. The bad news is that it appears to be inherent in 3D circles. – John Kormylo Dec 10 '16 at 13:19
  • As a quick fix, you can expand the bounding box using \path (0,0,0) circle (3.3); – John Kormylo Dec 10 '16 at 13:30
1

You can save the axis coordinate system and recreate it.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[xmin=-1,xmax=1,
        ymin=-1,ymax=1,
        zmin=0,zmax=1,
        clip=false]
        \coordinate (origin) at (axis cs: 0,0,0);
        \coordinate (xunit) at (axis cs: 1,0,0);
        \coordinate (yunit) at (axis cs: 0,1,0);
        \coordinate (zunit) at (axis cs: 0,0,1);
    \end{axis}
    \begin{scope}[shift={(origin)}]
      \pgfsetxvec{\pgfpointdiff{\pgfpointanchor{xunit}{center}}%
        {\pgfpointanchor{origin}{center}}}%
      \pgfsetyvec{\pgfpointdiff{\pgfpointanchor{yunit}{center}}%
        {\pgfpointanchor{origin}{center}}}%
      \pgfsetzvec{\pgfpointdiff{\pgfpointanchor{zunit}{center}}%
        {\pgfpointanchor{origin}{center}}}%

      \draw (0,0,0) circle (3);
    \end{scope}
  \draw (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}

demo

  • Your first code does unfortunately not compile on my system - I get an error complaining about a missing semicolon. I've tried some time but I couldn't figure it out, as I'm not familiar with the syntax. – winxi Dec 9 '16 at 19:12
  • The second approach seems to be a promising answer. However, if you make the circle wider (5 for example) it will be clipped in the upper region. Is this expected behavior? – winxi Dec 9 '16 at 19:13
  • The bounding box does include the cardinal points, like (0,5,0). One wonders just how circles are drawn. Using \addplot3 was much slower. – John Kormylo Dec 10 '16 at 13:54
  • In your code, if you want to recreate the very coordinate system from the axis, you have to interchange the arguments in the three calls of \pgfpointdiff. If you do this, you will get the same result as in my original post. Unfortunately, it seems that there is a principal problem with the bounding box calculation of 3D circles. – winxi Dec 11 '16 at 12:18

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.