7

I want to fix a contour plot at the top of a 3D box. The following code sets the contour plot to the base:

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
        width=0.9\textwidth,
        3d box,
        view={20}{8},
        plot box ratio=3 15 3,  
        colormap/jet,
        colorbar,
        ylabel={y},
        xlabel={x},     
        ]
\addplot3[raw gnuplot,   
      surf,
      samples=29,
      samples y=80,
      ] 
gnuplot[surf,
    ]{
    n=1e-5;
    b=100;
    h=10;
    p=-0.0001;
    set samples 29,80;
    set isosamples 29,80;
    K=((16*b**2)/(n*pi**3))*(-p);
Sum(i,x,y)=K*(((-1)**(0.5*((2*i-1)-1)))*(1-((cosh(((2*i-1)*pi*x)/(2*b)))/(cosh(((2*i-1)*pi*h)/(2*b)))))*((cos(((2*i-1)*pi*y)/(2*b)))/((2*i-1)**3)));
    u(i,x,y)=(i==0)?0:(u(i-1,x,y)+Sum(i,x,y));
    splot [-h:h] [-b:b] u(25,x,y)/u(25,0,0);
    };
\addplot[raw gnuplot,
      %thick,
      color=black,
      ]
gnuplot[]{
    set contour base;
    set cntrparam levels discrete 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9;
    unset surface;
    set isosamples 100;
    n=1e-5;
    b=100;
    h=10;
    p=-0.0001;
    K=((16*b**2)/(n*pi**3))*(-p);
Sum(i,x,y)=K*(((-1)**(0.5*((2*i-1)-1)))*(1-((cosh(((2*i-1)*pi*x)/(2*b)))/(cosh(((2*i-1)*pi*h)/(2*b)))))*((cos(((2*i-1)*pi*y)/(2*b)))/((2*i-1)**3)));
    u(i,x,y)=(i==0)?0:(u(i-1,x,y)+Sum(i,x,y));
    splot [-h:h] [-b:b] u(25,x,y)/u(25,0,0);
    };
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

I think the z filter doesn't work in this case. The gnuplot command "set xyplane" doesn't work in this context, too. Can I set the z level for this plot in any option? Is there a way to achieve the same result with less computing effort?

Jake
  • 232,450
  • Here is a note which is not directly related to your question: pgfplots 1.5 now comes with contour plot support - perhaps its contour prepared plot handler is a good choice here. – Christian Feuersänger Aug 23 '11 at 17:10
  • The manual for version 1.5 contains an example how to place a contour plot (or similar graphics object like a scatter plot) at a fixed z position. I believe the z filter stuff should work here. I am willing to look into it in the next days, but perhaps you find it before I have time... – Christian Feuersänger Aug 23 '11 at 17:12
  • thanks for your comment. I know the example - thats why i tested the z filter, but i used the raw gnuplot code and this doesn´t work directly with the contour gnuplot code. i´m still working on it and if i find a solution i´ll post it. – Mac-Cherony Aug 23 '11 at 17:56

1 Answers1

6

It works with

\addplot3[raw gnuplot,
      %thick,
      color=black,
      mesh=false,
        z filter/.code={\def\pgfmathresult{1}},
      ]
gnuplot[]{
    set contour base;
    set cntrparam levels discrete 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9;
    unset surface;
    set isosamples 100;
    n=1e-5;
    b=100;
    h=10;
    p=-0.0001;
    K=((16*b**2)/(n*pi**3))*(-p);
Sum(i,x,y)=K*(((-1)**(0.5*((2*i-1)-1)))*(1-((cosh(((2*i-1)*pi*x)/(2*b)))/(cosh(((2*i-1)*pi*h)/(2*b)))))*((cos(((2*i-1)*pi*y)/(2*b)))/((2*i-1)**3)));
    u(i,x,y)=(i==0)?0:(u(i-1,x,y)+Sum(i,x,y));
    splot [-h:h] [-b:b] u(25,x,y)/u(25,0,0);
    };

The differences to your approach are

  1. \addplot3 (the 3)

  2. mesh=false (we want line plots here)

  3. the z filter -- it was ignored in your example because the plot was treated as 2d plot -- in which case only x and y filters are considered.

You may also be interested in the alternative solution

\addplot3[raw gnuplot,
      %thick,
      color=black,
      contour prepared={labels=false},
      point meta=rawz,
        z filter/.code={\def\pgfmathresult{1}},
      ]

Here, contour prepared simply takes the contour of gnuplot. The point meta=rawz means to use the "unprocessed z coordinate" as color data (which is always called point meta in pgfplots). The unprocessed z coordinate is the one before the z filter comes into play.

Note that the approach with contour prepared works also with \addplot (i.e. without the 3, and without the point meta=rawz instruction). Note that it requires pgfplots 1.5 (which is fairly new).

Jake
  • 232,450
  • Thank you very much, that´s exactly what I want. I do not know why the z-filter-option hadn´t work in my code. But now it works :) Thank´s too for the alternative solution. I hadn´t thought about the point meta approach until now. – Mac-Cherony Aug 29 '11 at 17:55