我想创建一个钟形曲线,并在其周围添加一些解释性文字。但是我无法在注释中添加换行符,也无法在 Latex 中获取有关预期寿命的两段文本。到目前为止,我自己的代码也如下所示。
谢谢!
编辑:换行符的问题解决了!但是,我仍然不明白如何让图表下方的箭头显示增加/减少的预期寿命
\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}
答案1
这是一种方法,我给出name
轴,并axis
相对于其角在环境之后绘制箭头。
\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}