# Tikz with gaussian pdf

I am plotting a Hidden markov model its respective gaussian pdfs. The figure I am looking for is something like the one below. However, I would like to have 2D gaussian GMM rather than 3D gaussian pfds (it can be a mixture of 2 random pdf, there is no any specific mean or variance).

Here goes the code I have so far. Could someone explain to me how I can a figure to a node?

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{automata, positioning}

\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
\node[state] (s1) {state 1};
\node[state, right of=s1, xshift=4cm] (s2) {state 2};
\node[state, right of=s2, xshift=4cm] (s3) {state 3};
\node[draw=none, below of=s1, yshift=-1cm]   (g1)    {};
\node[draw=none, below of=s2, yshift=-1cm]   (g2)    {};
\node[draw=none, below of=s3, yshift=-1cm]   (g3)    {};
\node[draw=none, left of=s1, xshift=-0.5cm]   (b)    {};
\node[draw=none, right of=s3, xshift=0.5cm]   (e)    {};
\draw (s1) edge [auto=left] node {$p(q_t=2|q_{t-1}=1)$} (s2);
\draw (s2) edge [auto=left] node {$p(q_t=3|q_{t-1}=2)$} (s3);
\draw (s1) edge[loop above] node {$p(q_t=1|q_{t-1}=1)$} (s1);
\draw (s2) edge[loop above] node {$p(q_t=2|q_{t-1}=2)$} (s2);
\draw (s3) edge[loop above] node {$p(q_t=3|q_{t-1}=3)$} (s3);
%empty nodes
\draw (s1) edge [auto=left] node {$P(x_t|q_t=1)$} (g1);
\draw (s2) edge [auto=left] node {$P(x_t|q_t=2)$} (g2);
\draw (s3) edge [auto=left] node {$P(x_t|q_t=3)$} (g3);
\draw (b) edge node {} (s1);
\draw (s3) edge node {} (e);

\end{tikzpicture}
\end{document}

• Welcome to TeX.SE! Please provide us with an MWE. – user121799 Apr 23 '18 at 8:46

\documentclass[tikz]{standalone}
\usetikzlibrary{automata, positioning,calc,fit}
\tikzset{boxed/.style={path picture={
\coordinate (ll) at (path picture bounding box.south west);
\coordinate (ur) at (path picture bounding box.north east);
},% inspired by https://tex.stackexchange.com/a/423952/121799
}}
\begin{document}
\begin{tikzpicture}[samples=60,>=latex]
\node[state] (s1) {state 1};
\node[state, right of=s1, xshift=4cm] (s2) {state 2};
\node[state, right of=s2, xshift=4cm] (s3) {state 3};
% \node[draw=none, below of=s1, yshift=-1cm]   (g1)    {};
% \node[draw=none, below of=s2, yshift=-1cm]   (g2)    {};
% \node[draw=none, below of=s3, yshift=-1cm]   (g3)    {};
\node[draw=none, left of=s1, xshift=-0.5cm]   (b)    {};
\node[draw=none, right of=s3, xshift=0.5cm]   (e)    {};
\draw (s1) edge [auto=left] node {$p(q_t=2|q_{t-1}=1)$} (s2);
\draw (s2) edge [auto=left] node {$p(q_t=3|q_{t-1}=2)$} (s3);
\draw (s1) edge[loop above] node {$p(q_t=1|q_{t-1}=1)$} (s1);
\draw (s2) edge[loop above] node {$p(q_t=2|q_{t-1}=2)$} (s2);
\draw (s3) edge[loop above] node {$p(q_t=3|q_{t-1}=3)$} (s3);
%empty nodes
\draw (b) edge node {} (s1);
\draw (s3) edge node {} (e);
\begin{scope}[shift={($(s1) -(0,3cm)$)}]
\draw[boxed] plot[domain=-1.5:1.5] ({\x},{exp(-2*\x*\x)});
\node[fit=(ll) (ur),inner sep=1mm,draw] (plot1){};
\end{scope}
\begin{scope}[shift={($(s2) -(0,3cm)$)}]
\draw[boxed] plot[domain=-1.5:1.5] ({\x},{exp(-2*\x*\x)});
\node[fit=(ll) (ur),inner sep=1mm,draw] (plot2){};
\end{scope}
\begin{scope}[shift={($(s3) -(0,3cm)$)}]
\draw[boxed] plot[domain=-1.5:1.5] ({\x},{exp(-2*\x*\x)});
\node[fit=(ll) (ur),inner sep=1mm,draw] (plot3){};
\end{scope}
\draw (s1) edge [->,auto=left] node {$P(x_t|q_t=1)$} (plot1);
\draw (s2) edge [->,auto=left] node {$P(x_t|q_t=2)$} (plot2);
\draw (s3) edge [->,auto=left] node {$P(x_t|q_t=3)$} (plot3);
\end{tikzpicture}
\end{document}

• Hello marmot. Thanks for your answer! Unfortunately it is not working for me because the gaussian pdfs do not show below the states, but overlap. It's pretty chaotic! How can I place them below? I suppose it has to do with "\coordinate (ll) at (path picture bounding box.south west);" but I did not understand that part that well... – little_mice Apr 23 '18 at 9:58
• @little_mice I do not understand your question. Are you saying the output of my MWE is chaotic, or do you have trouble including your own Gaussians? – user121799 Apr 23 '18 at 13:25
• Ohh no worries, I have just solved the problem. Thank you anyway ;) – little_mice Apr 23 '18 at 17:46