5

I want to create a bell curve with some explanatory text around it. However I am unable to add linebreaks to the notes, and also failed to get the two texts about life expectancy in latex. My own code so far is below as well.

Thanks!

EDIT: The problems with the linebreaks are solved! However, I still dont understand how to get the arrows below the graph with Increasing/Decreasing life expectancy below them

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

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

\begin{tikzpicture}
\begin{axis}[
  no markers, domain=0:10, samples=1000,
  %axis lines*=left,
  axis y line=none,
  axis x line*=bottom,
  %xlabel=$x$, ylabel=$y$,
  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=6.25cm, width=15cm,
  xtick=\empty, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  grid = none
  ]
  \addplot [fill=cyan!20, draw=none, domain=6:7] {gauss(5,1.1)} \closedcycle;
 % \addplot [very thick,cyan!50!black] {gauss(4,1)};
  \addplot [very thick,cyan!50!black] {gauss(5,1.1)};


\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {Value of liabilities} (axis cs:6,0);
\draw[cyan!35] (axis cs:5,0) -- (axis cs:5,0.4);

\node[coordinate,pin=45:{Attachment point}]
at (axis cs:6,0.2399) {};
\node[coordinate,pin=45:{Detachment point}]
at (axis cs:7,0.06945) {};
\node[coordinate,pin=180:{Expected value \\ of liabilities}]
at (axis cs:5,0.39) {};


\end{axis}

\end{tikzpicture}
\end{document}

Tim
  • 97
  • 4
    Slightly different context, but the same thing about linebreaks in nodes applies as in http://tex.stackexchange.com/questions/179407/tikz-pgf-why-does-newline-and-not-split-text-in-node/179409#179409 – Torbjørn T. Dec 14 '16 at 15:30

1 Answers1

3

Here is one method, where I give a name to the axis, and draw the arrows after the axis environment, relative to its corners.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

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

\begin{tikzpicture}
\begin{axis}[
  name=myaxis, %%% <--- added
  no markers, domain=0:10, samples=100,
  %axis lines*=left,
  axis y line=none,
  axis x line*=bottom,
  %xlabel=$x$, ylabel=$y$,
  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=6.25cm, width=15cm,
  xtick=\empty, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  grid = none
  ]
  \addplot [fill=cyan!20, draw=none, domain=6:7] {gauss(5,1.1)} \closedcycle;
 % \addplot [very thick,cyan!50!black] {gauss(4,1)};
  \addplot [very thick,cyan!50!black] {gauss(5,1.1)};


\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {Value of liabilities} (axis cs:6,0);
\draw[cyan!35] (axis cs:5,0) -- (axis cs:5,0.4);

\node[coordinate,pin=45:{Attachment point}]
at (axis cs:6,0.2399) {};
\node[coordinate,pin=45:{Detachment point}]
at (axis cs:7,0.06945) {};
\node[coordinate,pin={[align=center]180:Expected value \\ of liabilities}]
at (axis cs:5,0.39) {};

\end{axis}

% add arrows with labels
\draw [<-] (myaxis.south west) ++(0,-1cm) -- node[below,align=center]{Decreasing life\\expectancy} ++(2cm,0);
\draw [<-] (myaxis.south east) ++(0,-1cm) -- node[below,align=center]{Increasing life\\expectancy} ++(-2cm,0);
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688