3

How can I fill the area under a curve in a 3d plot, similar to the \closedcycle command in ordinary 2d plots? Applying this command does a filling which is not rotated.

Minimal working example:

\documentclass{article} 
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
     \begin{axis}[
    xmin=0,xmax=3,
    zmin=0,zmax=2
    ]
        \addplot3[red,domain=0:1,fill=blue,opacity=0.5,samples y=0] (2,x,x^2) \closedcycle ;
     \end{axis}
  \end{tikzpicture}
\end{document}

In 2D it looks like this

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
  \begin{axis}[domain=0:1
    ]
        \addplot[red,domain=0:1,fill=blue,opacity=0.5,samples y=0] {x^2} \closedcycle ;
  \end{axis}
  \end{tikzpicture}
\end{document}

How can I easily apply this to a 3D plot?

Ludovic C.
  • 8,888
Harry
  • 31

2 Answers2

3

I suppose the answer is to add the required paths manually instead of \closedcycle.

In your case, it would be

\documentclass{standalone} 
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
     \begin{axis}[
    xmin=0,xmax=3,
    zmin=0,zmax=2
    ]
        \addplot3[red,domain=0:1,fill=blue,opacity=0.5,samples y=0] (2,x,x^2) -- (axis cs:2,1,0) -- (axis cs:2,0,0);
     \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

Unfortunately, both the meaning of \closedcycle and the use-case to "fill everything below the current parameterized plot" needs a careful definition. It would need a feature request if pgfplots should be able to do it automatically.

0

In the meantime Christian has added this feature to PGFPlots and your first given code in the question works fine without any modification, if you update PGFPlots to v1.13 and gives the result of Christians answer.

It also seems that there was a very similar question here.

Stefan Pinnow
  • 29,535