9

I am trying to create a 3D plot with custom z-ticks. However I can not create them with starting negative number. It works however as expected when the ticks start at 0.

My code is this one

\begin{tikzpicture}
\begin{axis}[view={30}{30},grid=major,
   /pgfplots/xtick={0,60,...,300},
   /pgfplots/ytick={0,60,...,300},
   /pgfplots/ztick={-1.0,0.2,...,1.0},
]
\addplot3[surf,domain=0:360,samples=40,
  colormap/jet,colorbar]
  {sin(x)*sin(y)};
\end{axis}
\end{tikzpicture}

with these results (the second with ztick={0,0.2,...,1.0}): enter image description here

enter image description here

How do I get correct z-ticks from -1 to 1 with steps 0.2?

1
  • 2
    within the axis environment the extra /pgfplots should not be needed – Martin H Nov 24 '11 at 14:07
14

The second number does not give the step size, but the next step. So try {-1.0,-0.8,...,1.0}, or, better, {-1.0,-0.8,...,-0.2,0.0,0.2,...,1.0} as in:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={30}{30},grid=major,
   /pgfplots/xtick={0,60,...,300},
   /pgfplots/ytick={0,60,...,300},
   /pgfplots/ztick={-1.0,-0.8,...,-0.2,0.0,0.2,...,1.0},
]
\addplot3[surf,domain=0:360,samples=40,
  colormap/jet,colorbar]
  {sin(x)*sin(y)};
\end{axis}
\end{tikzpicture}
\end{document}

I explicitly specified ...,-0.2,0.0,0.2,... because otherwise, you might get a tick of 10^{-5} instead of 0.

result

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.