# Rotated Normal Distribution

Im trying to create a rotated normal distribution similar to this:

but I'm stuck at trying to separate the curves from each other; this is what I have so far. Would really appreciate any help.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{mathtools,amssymb}
\usepackage{tikz}
\usepackage{xcolor}
\pgfplotsset{compat=1.7}
\begin{document}
\pgfmathdeclarefunction{gauss}{2}{\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{tikzpicture}

\begin{axis}[anchor=origin, % Shift the axis so its origin is at (0,0)
rotate around={-90:(current axis.origin)}, % Rotate around the origin
no markers, domain=0:10, samples=100,
axis x line*=bottom,
axis lines=none, % Axis lines going through the origin
height=5cm, width=5cm, ytick=\empty, xtick={0},
enlargelimits=false, clip=false, axis on top,
grid = major]
\end{axis}

\begin{axis}[anchor=(0,10), % Shift the axis so its origin is at (0,0)
rotate around={-90:(current axis.origin)}, % Rotate around the origin
no markers, domain=0:10, samples=100,
axis x line*=bottom,
axis lines=none, % Axis lines going through the origin
height=5cm, width=5cm, ytick=\empty, xtick={0},
enlargelimits=false, clip=false, axis on top,
grid = major]
\end{axis}

\draw (-2,-6) -- (9,-6);

\end{tikzpicture}
\end{document}


Welcome to TeX.SE! Are you looking for something like this?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[font=\sffamily,
declare function={gauss(\x,\y,\z)=1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\begin{axis}[samples=101,smooth,hide axis,width=12cm]

\draw (0,-3) --  (0,3) coordinate[pos=0.4](x1) coordinate[pos=0.5] (y1);
\draw (1,-2) -- (1,4) coordinate[pos=0.6](x2) coordinate[pos=0.5] (y2);
\draw (2,-3) -- (2,3) coordinate[pos=0.6](x3) coordinate[pos=0.5] (y3);
\path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
\coordinate (t) at (3,-4.1);
\end{axis}
\foreach \X in {1,2,3}
{\fill (x\X) circle (2pt);
\draw ([xshift=-1mm]y\X) -- ([xshift=1mm]y\X);
\draw ([yshift=1mm]z\X) -- ([yshift=-1mm]z\X) node[below] {$\X$};}
\node[anchor=north east] at (t) {time};
\draw[blue,thick,shorten >=2mm,shorten <=2mm] (x1) -- (x2);
\draw[blue,thick,shorten >=2mm,shorten <=2mm] (x2) -- (x3);
\end{tikzpicture}
\end{document}


• Is there any reason you want to use version 1.7? If so, one may have to slightly modify the syntax by adding axis cs: to some coordinates.
• I modified the way the Gaussian function is declared to a syntax that is arguably a bit easier to deal with.
• The main point, though, is that instead of rotating the axis I just use parametric plots. In my opinion this makes things simpler. If you insist on rotating axis environments, this can also be done, however then one faces usually the problem that the interpretations of above etc. become a bit unintuitive.
• As you see, I do most of the things with TikZ "only". In principle one could do this without pgfplots, but the price one may have to pay is that things like changing the size of the plot will become a tiny bit more complicated.
• I kicked out packages that were not needed here. (Note that pgfplots loads TikZ.)

• I added a parameter \offset that "detaches" the plots from the vertical lines.

• You can adjust the width and height of the plot. If you make it wider, there will be more white space between the plots. If you, at the same time, multiply the Gauss functions by some number smaller than 1, e.g. declare function={gauss(\x,\y,\z)=\offset+0.8/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}, where I replaced 1 by 0.8, the gaps can be further increased.

• I use the standalone class for the code below. You can then either compile the file on its own (e.g. with pdflatex), which will produce a pdf file that can be included in the main document via \includegraphics. Or you may use \includestandalone[mode=tex]{<file.tex>} provided that you use \usepackage{standalone} in your main document. My personal favorite for plots of low complexity and compilation time would be to make sure that you load pgfplots by adding \usepackage{pgfplots} and \pgfplotsset{compat=1.16} in the preamble of the main document, and then just copy the stuff \begin{tikzpicture}...\end{tikzpicture} to the main document, preferably wrapped in a figure environment. Notice, however, that I never have used overleaf, so I can't help you with overleaf related questions.

Here are code and output:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\pgfmathsetmacro{\offset}{0.05}
\begin{tikzpicture}[font=\sffamily,
declare function={gauss(\x,\y,\z)=\offset+1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\begin{axis}[samples=101,smooth,hide axis,width=15cm,height=8cm]

\draw[-latex] (0,-3) --  (0,3) coordinate[pos=0.4](x1) coordinate[pos=0.5] (y1)
node[below right,rotate=-90]{$x(t_i)$};
\draw[-latex] (0,-3) -- (0.5,-3) node[below left,rotate=-90]{$f\bigl(x(t_i)\bigr)$};
\draw (1,-2) -- (1,4) coordinate[pos=0.6](x2) coordinate[pos=0.5] (y2);
\draw (2,-3) -- (2,3) coordinate[pos=0.6](x3) coordinate[pos=0.5] (y3);
\path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
\coordinate (t) at (3,-4.1);
\coordinate (xi) at (-0.6,4);
\end{axis}
\foreach \X in {1,2,3}
{\fill (x\X) circle (2pt);
\draw ([xshift=-1mm]y\X) -- ([xshift=1mm]y\X);
\draw ([yshift=1mm]z\X) -- ([yshift=-1mm]z\X) node[below] {$\X$};}
\node[anchor=north east] at (t) {time};
\node[anchor=north east] at (xi) {$x(t)$};
\draw[blue,thick,shorten >=2mm,shorten <=2mm] (x1) -- (x2);
\draw[blue,thick,shorten >=2mm,shorten <=2mm] (x2) -- (x3);
\end{tikzpicture}
\end{document}


• Hi Marmot- thanks a ton thats awesome it looks great ! just one small comment; is there anyway to detach the x-axis from the plot very slightly like in the posted diagram? thanks again, r – user171006 Sep 25 '18 at 20:48
• also how would i control the horizontal space between 1, 2 & 3? id like to add some whitespace between the 3 plots if possible .. – user171006 Sep 25 '18 at 20:55
• finally if i want to include the diagram generated by the above code in another tex files on overleaf how would i go about doing that? i tried \input{figures_tikz/stochastic_processes.tex} but it fails .. – user171006 Sep 25 '18 at 21:14
• Thanks again Marmot. One last thing Im trying to do is throw some text and a mini y-axis on one of the curves but having trouble rotating the text and axis 90 degrees. I've highlighted what I'm trying to do in an image I've added to my original question. I'm able to add coordinates and lines but what I'm struggling to figure out is how to add a tha mini-rotated-yaxis in relative coordinates to the curve? – user171006 Oct 8 '18 at 13:59