3

Here is a minimal working example:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
   \begin{axis}[samples=60]
      %\addplot3[surf, domain=-2:2] {x^2-y^2};
      % y=constant grids lines
      \foreach \yy in {-2.0,-1.0,...,2.0}
      {
         \addplot3[domain=-2:2, line width=0.1mm, mark=none, color=red]
         ({x}, {\yy}, {x^2-\yy*\yy});
      }
   \end{axis}
\end{tikzpicture}
\end{document}

The plot is here: enter image description here

The question is: Why is pgfplots joining my first and last sample values? The horizontal lines on top should not be there. The equation plotted here is the saddle x^2-y^2=z. In the code I fixed $y=-2,-1,0,1,2$, and varied x between -2 and 2.

Thanks.

  • Are you trying to draw a mesh? Then you can simply go \addplot3[surf,mesh,domain=-2:2, line width=0.1mm, mark=none, color=red]({x}, {y}, {x^2-y^2}); – percusse Nov 13 '15 at 23:09
  • @percusse : I was trying to draw half shaded sphere with no mesh. Then I dived into this post : http://tex.stackexchange.com/questions/39889/tikz-how-to-get-a-few-smooth-grid-lines-for-surface-plots . You suggested to use "\addplot3[surf, shader=interp] to "delete" the mesh (thanks for that, that is what I was looking for). However, Kristin wanted to have control of the mesh. I did that here and the mesh is where I want it to be but then I get those horizontal lines on top. – Herman Jaramillo Nov 13 '15 at 23:16

1 Answers1

2

The parameter "samples y=0" solved my problem. Here is the code and the figure:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
   \begin{axis}[samples=60]
      %\addplot3[surf, domain=-2:2] {x^2-y^2};
      \foreach \xx in {-2.0,-1.0,...,2.0}
      {
      \addplot3+[domain=-2:2, line width=0.1mm, mark=none, color=black, xlabel=$x$,
      samples y=0, color=red]
         ({\xx}, {x}, {\xx*\xx-x^2});
      }

      % y=constant grids lines
      \foreach \yy in {-2.0,-1.0,...,2.0}
      {
         \addplot3[domain=-2:2, line width=0.1mm, mark=none, color=black, samples y=0,
         color=red]
         ({x}, {\yy}, {x^2-\yy*\yy});
      }


   \end{axis}
\end{tikzpicture}
\end{document}

enter image description here