0

I'd like to plot different bivariate Gaussian distributions as shaded 2D ellipses at different points in 3D space. The 2D ellipses I would plot like Jake suggests in Gaussian ellipsoids using tikz, but technically that is already a 3D plot. Is there a possibility to extend this method?


I came up with the following example (left: example how I like the ellipses to be orientated, taken from https://arxiv.org/abs/1611.03986, right: my ansatz):

enter image description hereOutput of above .tex-file

Two main points are that

  • the colormap is not actually transparent and one cannot see the axis of the outer coordinate system any more,
  • and that I would like to have the ellipses at a fixed point y in the xz-plane (this means that the bottom line of the black rectangles should be parallel to the x-axis and compressed accordingly).
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{%
    colormap={whitered}{color(0cm)=(transparent); color(1.cm)=(red)}%
}
\begin{document}
\begin{tikzpicture}[baseline,
    declare function={bivar(\ma,\sa,\mb,\sb)=
        1/(2*pi*\sa*\sb) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2))/2;}]
% Outer coordinate system
\begin{axis}[
    unit vector ratio*=1 1 1,
    axis lines = middle,
    view={120}{30},
    domain = -10:10,
    zmin = -5, zmax = 5,
    xlabel = $x$, ylabel = $y$, zlabel = $z$,
    x label style={at={(ticklabel* cs:1.)},anchor=north east},
    y label style={at={(ticklabel* cs:1.)},anchor=north west},
    z label style={at={(ticklabel* cs:1.)},anchor=south},
    ]
    \coordinate (origin1) at (axis cs:0,-10,0);
    \coordinate (origin2) at (axis cs:0,10,0);
    \addplot3[no markers,opacity=0]{0}; % <- without this pseudo plot, the outer coordinate system does not work
\end{axis}
% Bivariate distribution 1
\begin{axis}[
    at={(origin1)}, anchor={center},
    width=3cm, height=3cm,
    scale only axis,
    axis equal image,
    hide axis,
    colormap name=whitered,
    view={0}{90},
    enlargelimits=false,
    domain=-1.5:1.5, y domain=-1.5:1.5,
    ]
    \addplot3 [surf, draw=none, samples=19, shader=interp, patch type=bilinear] {bivar(0,.1,0,.6)};
\end{axis}
% Bivariate distribution 2
\begin{axis}[
    at={(origin2)}, anchor={center},
    width=3cm, height=3cm,
    scale only axis,
    axis equal image,
    hide axis,
    colormap name=whitered,
    view={0}{90},
    enlargelimits=false,
    domain=-1.5:1.5, y domain=-1.5:1.5,
    ]
    \addplot3 [surf, draw=none, samples=19, shader=interp, patch type=bilinear] {bivar(0,.2,0,.3)};
\end{axis}
\end{tikzpicture}
\end{document}
  • 2
    Welcome to TeX.SE! What have you tried so far? – user156344 Mar 19 '19 at 12:38
  • 2
    I think you need to add the beginning of a MWE. – JeT Mar 19 '19 at 13:03
  • I'm not really asking for a complete solution, rather for a way to tackle the problem. Jake's mentioned answer depends on having a certain angle onto a coloured 3D plot, which is not feasible the way I want to do it. The only way I can think of is produce separate image files of the ellipses and insert them sheared and at different positions in a new 3D plot. – dodi Mar 19 '19 at 13:19
  • 1
    @dodi please dont add external links, if you want to add images/codes please do that so within this site. Other links tend to die over-time. Moreover, please show us what you have tried so-far, atleast something for us to being with. I think that would really be helpful, instead of us starting everything from scratch. – Raaja_is_at_topanswers.xyz Mar 19 '19 at 13:47
  • Answer to your question: yes, it is possible. If you want a more detailed answer, consider writing a more detailed question with some code that shows what you've tried and has some data in such that the one writing an answer does not have to make it up. – user121799 Mar 19 '19 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.