7

enter image description here

I try to draw a generic Gaussian over a ray, to indicate a possible generic trend. At the moment I have managed to draw both the ray and the Gaussian, but I can't get it to lay on the ray, as changing the coordinates changes the whole graph. In the image it is as I would like it to look, as it came is in the code.

\documentclass[border=2cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

\begin{tikzpicture}
\begin{axis}[
  no markers, 
  domain=0:6, 
  samples=100,
  ymin=0,
  xmin=0,
  axis lines*=left, 
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=12cm, 
  width=12cm,
  xtick=thick, 
  ytick=thick,
  enlargelimits=false, 
  clip=false, 
  axis on top,
  grid = major,
  ]
\begin{scope}[yshift=-\pgflinewidth]

\clip (axis cs:0,0) rectangle (axis cs:6,1);
\addplot [draw=none,fill=lightgray!50!] {gauss(x, 3, 0.8)};
\end{scope}



\addplot [very thick,black!50!] {gauss (x, 3, 0.8)};
\pgfmathsetmacro\valueB{gauss(1,3,0.09)}
\pgfmathsetmacro\valueA{gauss(1,3,0.8)}
\pgfmathsetmacro\valueC{gauss(1,3,0.8)}

\node[coordinate, pin={Spatial and cognitive distance}] at (axis cs: 3, 0.5){};

\addplot[black!50!, thick](x,x); 

\end{axis}

\end{tikzpicture}
\end{document}

Any tips? Thanks a lot <3

11

Welcome to TeX.SE!!!

If you can use a TikZ picture, it would be very easy. You only have to draw you gaussian function and rotate it.

Like the following example:

\documentclass[border=2mm,tikz]{standalone}

\pgfmathdeclarefunction{gauss}{3}{\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}}

\begin{document}
\begin{tikzpicture}
% grid
\draw[help lines]  (0,0) grid[step=0.5] (6,6);
% axes
\draw[latex-latex] (0,6) node [above] {$y$} |- (6,0) node [right] {$x$};
% gaussian function
\draw[rotate=45,red,fill=red,fill opacity=0.2] plot[domain=0:{6*sqrt(2)},samples=100] (\x,{gauss(\x,{3*sqrt(2)},0.7)});
% line
\draw (0,0) -- (6,6);
% axes labels
\foreach\i in {1,...,5}
{
  \node at (\i,0) [below] {$\i$};
  \node at (0,\i) [left]  {$\i$};
}
\end{tikzpicture}
\end{document}

enter image description here

4
  • Wow thank you so much I didn't know about the possibility of rotating the function. Thank again! Oct 18 at 18:55
  • +1: Does the curly bracket syntax {6*sqrt(2)} works out of the box? Oct 19 at 8:26
  • 1
    @Dr.ManuelKuehner, thanks!! Do you mean without the curly brackets? Yes, it works, I put the curly brackets without thinking, because they are always needed in TikZ coordinates. Oct 19 at 8:35
  • Ah, I was assuming that the curly brackets are needed when a calculation is required. Oct 19 at 9:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.