3

I am drawing a 3D-Bessel function using pgfplots and gnuplot. What I am trying to do is plot on top of the 3d box, a projection of the 3d function.

I thought of using a contour gnuplot plot, but although using a high number of contours, I cannot fill the entire surface of the projection, as seen in the following image

enter image description here

Any idea on how to avoid the gaps and have a smoothly filled projection?

The image was made using the following code

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usepgfplotslibrary{patchplots}

\begin{document}  
\begin{tikzpicture}
    \begin{axis}    [width=\textwidth,
                     height=\textwidth,
                     ultra thick,
                     colorbar,
                     colorbar style={yticklabel style={text width=2.5em,
                                                      align=right,
                                                  /pgf/number format/.cd,
                                                   fixed,
                                                   fixed zerofill,
                                                   precision=1,
                                                   },
                                    },
                     xlabel={$\rho_x=k_xr_x$},
                     ylabel={$\rho_y=k_yr_y$},
                     zlabel={$j_l(\rho)$},
                     3d box,
                     zmax=2.5,
                     xmin=-3, xmax=3,
                     ymin=-3.1, ymax=3.1,
                     ytick={-3, -2, ..., 3},
                     grid=major,
                     grid style={line width=.1pt, draw=gray!30, dashed},
                     x tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                     y tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                     z tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                    ]
        \addplot3[surf, 
                      shader=interp,
                      mesh/ordering=y varies,
                      domain=-3:3,
                      y domain=-3.1:3.1,
                      ]
             gnuplot {besj0(x**2+y**2)};

        \addplot3[contour gnuplot={output point meta=rawz,
                                      number=1000,
                                   labels=false,},
                  z filter/.code={\def\pgfmathresult{2.5}},
                  domain=-3:3,
                  y domain=-3:3]
         gnuplot {besj0(x**2+y**2)};

    \end{axis}
\end{tikzpicture}

\end{document}
0

1 Answer 1

5

Instead of a contour plot I would plot a constant with the point meta of the original plot.

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

\begin{document}  
\begin{tikzpicture}
    \begin{axis}    [width=\textwidth,
                     height=\textwidth,
                     ultra thick,
                     colorbar,
                     colorbar style={yticklabel style={text width=2.5em,
                                                      align=right,
                                                  /pgf/number format/.cd,
                                                   fixed,
                                                   fixed zerofill,
                                                   precision=1,
                                                   },
                                    },
                     xlabel={$\rho_x=k_xr_x$},
                     ylabel={$\rho_y=k_yr_y$},
                     zlabel={$j_l(\rho)$},
                     3d box,
                     zmax=2.5,
                     xmin=-3, xmax=3,
                     ymin=-3.1, ymax=3.1,
                     ytick={-3, -2, ..., 3},
                     grid=major,
                     grid style={line width=.1pt, draw=gray!30, dashed},
                     x tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                     y tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                     z tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                    ]
        \addplot3[surf, samples=51,
                      shader=interp,
                      mesh/ordering=y varies,
                      domain=-3:3,
                      y domain=-3.1:3.1,
                      ]
             gnuplot {besj0(x**2+y**2)};

        \addplot3[surf, samples=51,
                      shader=interp,
                      mesh/ordering=y varies,
                      domain=-3:3,
                      y domain=-3.1:3.1,
                      point meta=rawz,
                      z filter/.code={\def\pgfmathresult{2.5}},
                      ]
             gnuplot {besj0(x**2+y**2)};


    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

If you use a polar plot, IMHO the result becomes even more appealing.

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

\begin{document}  
\begin{tikzpicture}
    \begin{axis}    [width=\textwidth,
                     height=\textwidth,
                     ultra thick,
                     colorbar,
                     colorbar style={yticklabel style={text width=2.5em,
                                                      align=right,
                                                  /pgf/number format/.cd,
                                                   fixed,
                                                   fixed zerofill,
                                                   precision=1,
                                                   },
                                    },
                     xlabel={$\rho_x=k_xr_x$},
                     ylabel={$\rho_y=k_yr_y$},
                     zlabel={$j_l(\rho)$},
                     3d box,
                     zmax=2.5,
                     xmin=-3, xmax=3,
                     ymin=-3.1, ymax=3.1,
                     ytick={-3, -2, ..., 3},
                     grid=major,
                     grid style={line width=.1pt, draw=gray!30, dashed},
                     x tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                     y tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    },
                     z tick label style={/pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=1
                                    }, 
                    data cs=polar,
                    ]
        \addplot3[surf, samples=51,
                      shader=interp,
                      z buffer=sort,
                      %mesh/ordering=y varies,
                      domain=0:360,
                      y domain=3.1:0,
                      ]
             gnuplot {besj0(y**2)};

        \addplot3[surf, samples=51,
                      shader=interp,
                      %mesh/ordering=y varies,
                      domain=0:360,
                      y domain=0:3.1,
                      point meta=rawz,
                      z filter/.code={\def\pgfmathresult{2.5}},
                      ]
             gnuplot {besj0(y**2)};


    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

1
  • Thank you very much for your help! I think I prefer the first way, because you see the folding easier however on the expense of having a not smooth projection. I will write another question about that!
    – Thanos
    Commented Feb 24, 2019 at 16:21

You must log in to answer this question.

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