2

Unfortunately the TikZ-manual is a bit complicated to understand about this point.

Assumed we have some kind of squared 3D graph like this one:

Minimum Working Example (MWE):

\documentclass{standalone}
\usepackage{tikz, pgfplots}

\begin{document}

\begin{tikzpicture}
   \begin{axis}[samples=20]
      \addplot3[surf, domain=-2:2] {-x^2-y^2};
   \end{axis}
\end{tikzpicture}

\end{document}

Screenshot of the result:

Visualization of pipe flow


  1. How can I replace the current graph with some 4th degree polynomial formula in both directions x and y, e.g. x^4-2*x^2 and y^4-2*y^2
  2. How can I set the domain for x- and y-axis from -1 to +1 and the domain for z-axis from 0 to +1?

Just for explanation: The desired picture should visualize flow velocity distribution of pipe flow through porous media (where the flow velocity is highest at the border areas). While in empty pipe flow the velocity reaches its maximum in the center, this is different in porous media what I want to display with the graph.

Typical pipe flow (as 2D model):

Typical pipe flow

Typical pipe flow through porous media (as 2D model):

Flow through porous media

Please do not pay attention to the x- and y-shifts. The graph should be centered.

  • What precisely do you mean by "in both directions"? You can plot arbitrary functions with e.g. ` \addplot3[surf, domain=-2:2] {x^4-2*x^2};.The domains can be set with domain=-1:1` and (if the y domain is different) domain y=-1:1. – user121799 Jan 26 at 21:55
5

A few things:

  1. The relevant manual here is probably the one of pgfplots, not TikZ.
  2. You can plot arbitrary functions.
  3. You are already setting a domain. If you want to have a different domain for y, use domain y=....
  4. You can add zmin and zmax to set the range of the z axis.

These things get illustrated in the MWE.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}
   \begin{axis}[samples=20,zmin=0,zmax=1]
      \addplot3[surf, domain=-1:1] {(x^4-2*x^2)*(y^4-2*y^2)};
   \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

I do not quite understand what is meant by "in both directions", so I guessed what it might mean.

  • I am very sorry for my bad explanation, so I've updated my question to clarify the desired sculpture. Thanks a lot for your help! – Dave Jan 27 at 9:58
  • Due to your great explanation, I will accept this as an answer but ask for a different shape in a further topic. I hope this is okay for you? – Dave Jan 27 at 11:12

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.