3

I want to draw the surface x^2-y in PGFplots in 3D and intersect it with the plane z=1, emphasizing the intersection probably with some coloration or shading or something. I'd also like to emphasize the y-axis and the z-axis.

I've read a few similar posts on here and tried to edit them, but I can't seem to get them into the shape I want. Does anyone have a suggestion for something I can try?

EDIT:

I've been working up a minimum working example of the code, where the intersection is not at all emphasized. Also, I've read elsewhere now that there are problems drawing intersections with PGFplots and that sometimes PStricks is better. I'm fine with either solution, I just want something that works.

\documentclass[12pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture} 
\begin{axis}
[
    xlabel = $x_1$,
    ylabel = $x_2$,
    zlabel = $x_3$,
    zlabel style={rotate = -90},
    zmin = 0, zmax = 2
] 
\addplot3[surf,mesh,shader=faceted,samples=20] (x,y,1);
\addplot3[surf,shader=interp,samples=50] {x*x - y}; 
\end{axis} 
\end{tikzpicture}
\end{document}

The result looks like crap in my opinion, but I have no idea how to make it look nice.

code example

1

1 Answer 1

6

Here’s a kind of hackish pair of solutions that required a bit of algebra. There’s a library in pgfplots, fill between, which does intersections and fills for 2-d plots but doesn’t seem to work for this.

The first image draws the plane after the surface and then adds an intersection line manually. The second rewrites the equation for the surface as two parameterized surfaces, one above the plane of intersection and one below.

\documentclass[12pt]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{pgfplots}

\pgfplotsset{compat=1.12}

\pgfplotsset{ colormap={below}{rgb255(0cm)=(127, 255, 212); rgb255(1cm)=(100, 149, 237)} }
\pgfplotsset{ colormap={above}{rgb255(0cm)=(100, 149, 237,128); rgb255(1cm)=(65, 105, 225,128)} }

\begin{document}
\begin{tikzpicture} 
\begin{axis}
[
    xlabel = $x_1$,
    ylabel = $x_2$,
    zlabel = $x_3$,
    zlabel style={rotate = -90},
    xmin = -4, xmax = 4,
    ymin = -5, ymax = 5,
    zmin = 0, zmax = 2
] 
\addplot3 [surf,shader=faceted,samples=50,colormap/cool] {x*x - y}; 
\addplot3 [mesh,samples=20,color=DimGray] (x,y,1);
\addplot3[samples y=0,domain=-sqrt(6):sqrt(6),color=DarkCyan]({x}, {x*x - 1}, {1});
\end{axis} 
\end{tikzpicture}

\begin{tikzpicture} 
\begin{axis}
[
    xlabel = $x_1$,
    ylabel = $x_2$,
    zlabel = $x_3$,
    zlabel style={rotate = -90},
    xmin = -4, xmax = 4,
    ymin = -5, ymax = 5,
    zmin = 0, zmax = 2,
] 
\addplot3 [surf,shader=interp,samples=50,variable=\u,variable y=\v,domain=-sqrt(6):sqrt(6),y domain=0:1,colormap name=below] ({u},{u*u-v},{v});
\addplot3 [mesh,samples=20,color=DimGray] (x,y,1);
\addplot3 [mesh,samples=20,variable=\u,variable y=\v,domain=-sqrt(6):sqrt(6),y domain=1:2,colormap name=above] ({u},{u*u-v},{v});
\end{axis} 
\end{tikzpicture}
\end{document}

enter image description here

6
  • Wow, looks great! Thanks for your response. I really like the second one, I'm going to play around with it and see if I can improve on it just a bit. I'd like to emphasize the intersection even more -- maybe draw the parabola extra thick and in red or something -- and move the axes around. For the record, I'm doing some algebraic geometry and since everything's just in 3D here, it's actually visualizable, so I thought I'd try to actually picture what was going on.
    – walkar
    Sep 5, 2015 at 23:49
  • Glad you like it. You could move the third \addplot3 from the first image to the second to get the intersection line there, and color it whatever you want.
    – Davislor
    Sep 6, 2015 at 0:09
  • Ahead of you on that one. Now I'm trying to draw the axes exactly how I want them, since they're also part of this particular zero locus. I'm just about satisfied with it -- I'll post a link to it soon.
    – walkar
    Sep 6, 2015 at 0:10
  • 1
    after some toying around, I finally came up with this: i.imgur.com/Ao2UFwU.png It's not spectacular (in particular, I wish I could rotate the z-axis one way or the other after playing around with the view = {x}{y} setting) but much, much better than it was. Thanks so much!
    – walkar
    Sep 6, 2015 at 0:28
  • Any rotation around the z-axis can be expressed as a composition of those two rotations. Just find its axis-angle representation in SO(3).
    – Davislor
    Sep 6, 2015 at 0:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .