I'm looking for a way to do this kind of pictures with pgfplots. More precisely I need to make 2 pictures :

  • one to draw any 3D shape with a vertical plane (with some transparency) cutting it

1st image or 2nd image

  • one to draw the same 3D shape cutted by the same plane but only showing the curve on one side of the plane. The main goal is to see the 2D restriction of the curve over a plane / the intersection of the plane and the curve.

3rd image

Does anyone have an idea?

first image

second one

Sources :



closed as too broad by egreg, Troy, Henri Menke, Stefan Pinnow, TeXnician Sep 24 '18 at 5:59

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please show us what you have tried and note that not all users here are familiar with matlab. Notice also that pgfplots is not a computer algebra system. – user121799 Sep 23 '18 at 21:32

This might not be an answer to your question. One reason why I cannot answer this question is that I do not know matlab. The other reason is that it seems to me that you are asking several questions at a time. So I focus on the question

Can one add a plane to a 3D plot made by pgfplots?

The answer is

Yes ...

... if you are willing to do things step by step.

Starting point of my answer is an example from pgfplots.net by Stefan Kottwitz, which I slightly modified. The most important change I made was to change the border from 15pt to 3.14mm. And then I changed a sign, used declare function to simplify things a bit, and (I almost forgot) also added a plane.

\begin{tikzpicture}[declare function={f(\x,\y)=8-(\x*\x+\y*\y)/4;}]
  \pgfdeclarelayer{pre main}
  \pgfsetlayers{pre main,main}
      hide axis,
      domain = -4:4,
      zmax   = 12,
    \begin{pgfonlayer}{pre main}
      \addplot3 [surf] {f(x,y)};
    \addplot3 [name path = xline, draw = none] (x,-4,0);
    \addplot3 [name path = yline, draw = none] (4,y,0);
    \addplot3 [name path = xcurve, y domain = 0:0, draw = none]
      (x, -4, {f(x,4)});
    \addplot3 [name path = ycurve, y domain = 0:0, draw = none]
      (4, x, {f(x,4)});
    \addplot [left color = black, right color = black!50, draw = none]
      fill between[of = xcurve and xline];
    \addplot [left color = black!50, right color = black, draw = none]
      fill between[of = yline and ycurve, reverse = true];
    \fill[gray!20,opacity=0.314] plot[variable=\x,smooth,samples=25,domain=-4:2] (0,\x,{f(\x,0)})
    to[out=0,in=162,tension=1.2] (0,4,{4.78})
    -- (0,4,12) -- (0,-4,12) -- cycle;

enter image description here

  • Thank you marmot, I precised a bit more the question. I would like to show what happened / what is the 2D shape when cutting a curve with a plane. I really know that tikz-pgf is not a CAS and I'm ready to provide to it any needed curve equation – Yoshi Sep 24 '18 at 6:39
  • @Yoshi Your question has unfortunately been closed. In my above example, it is trivial to show the surface at the cut because I chose the cutting plane along some fixed x, here x=0. Consequently, the function will just be f(0,y). In general, it is slightly more tricky, but not much. I was actually working at something that draws the plane in the general case, but before I finished your question was closed. – user121799 Sep 24 '18 at 14:33
  • I've seen that I need any moderator or user who ask the post to be holded for it to be reopened but I'n not pretty sure on how to contact them. – Yoshi Sep 24 '18 at 17:27
  • @Yoshi At present, there are 2 reopen votes, one from me. I am not too optimistic that this will work out. Part of the reason is that you changed your question rather late, so it is already out of the focus of many. I don't know what the "cleanest" way to go is, but one possibility is that you ask a new question (and do whatever you think is appropriate with my answer, i.e. accept it or let it be). If you decide to do so, try to make the question as specific as possible. – user121799 Sep 24 '18 at 17:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.