\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}[every pin edge/.style={<-},]
\begin{axis}[
no markers,
domain=0:6,
samples=100,
ymin=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=5cm,
width=12cm,
xtick=\empty,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
grid = major,
hide y axis
]
\begin{scope}[yshift=-\pgflinewidth]
\clip (axis cs:1,0) rectangle (axis cs:2,0.24);
\addplot [draw=none,fill=orange] {gauss(x, 3, 1)};
\end{scope}
\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};
\pgfmathsetmacro\valueB{gauss(1,1,7)}
\pgfmathsetmacro\valueA{gauss(1,1,1.65)}
\pgfmathsetmacro\valueC{gauss(1,1,1)}
\draw [very thick, blue] (axis cs:1,0) -- (axis cs:1,\valueB);
\draw [very thick, blue] (axis cs:2,0) -- (axis cs:2,\valueA);
\draw [very thick, blue] (axis cs:3,0) -- (axis cs:3,\valueC);
\node[below] at (axis cs:3,0) {0};
\node[coordinate,pin=86:{Probability distribution of expected returns in the set period}]
at (axis cs:4,0.25) {};
\node[coordinate,pin=100:{$\alpha$}]
at (axis cs:1.4,0.1) {};
\node[coordinate,pin=270:{Expected Shortfall}]
at (axis cs:1.6,0) {};
\node[coordinate,pin=86:{Value at Risk}]
at (axis cs:2,0) {};
\end{axis}
\end{tikzpicture}
\end{document}
虽然正态曲线的大小、标记箭头的大小、标记箭头的位置和标记文本(例如收益分布的概率……文本延伸到右侧,这是我不希望看到的)需要进行一些调整,但它产生的效果接近我想要的效果。下图显示了使用 MWE 获得的输出:
答案1
要更改箭头提示,我建议加载arrows.meta
库。然后你就可以使用了every pin edge/.style={Stealth-}
。
要将图钉标签拆分为多行,必须将其对齐。您可以在同一位置对图钉位置进行其他调整:
\node[coordinate,
pin={[align=right, anchor=south, pin distance=5mm]
above right:{Probability distribution\\of Returns expected\\in the set period}}]
at (axis cs:4,0.25) {};
您可以使用xscale
它来扩大情节范围。
以下是代码:
\documentclass[border=2cm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\pgfplotsset{compat=1.8}
\begin{document}
\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}
\begin{tikzpicture}[every pin edge/.style={Stealth-},]
\begin{axis}[xscale=1.5,
no markers,
domain=0:6,
samples=100,
ymin=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=5cm,
width=12cm,
xtick=\empty,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
grid = major,
hide y axis
]
\begin{scope}[yshift=-\pgflinewidth]
\clip (axis cs:1,0) rectangle (axis cs:2,0.24);
\addplot [draw=none,fill=orange] {gauss(x, 3, 1)};
\end{scope}
\addplot [very thick,cyan!50!black] {gauss(x, 3, 1)};
\pgfmathsetmacro\valueB{gauss(1,1,7)}
\pgfmathsetmacro\valueA{gauss(1,1,1.65)}
\pgfmathsetmacro\valueC{gauss(1,1,1)}
\draw [very thick, blue] (axis cs:1,0) -- (axis cs:1,\valueB);
\draw [very thick, blue] (axis cs:2,0) -- (axis cs:2,\valueA);
\draw [very thick, blue] (axis cs:3,0) -- (axis cs:3,\valueC);
\node[below] at (axis cs:3,0) {0};
\node[coordinate, pin={[align=right, anchor=south, pin distance=5mm]above right:{Probability distribution\\of Returns expected\\in the set period}}]
at (axis cs:4,0.25) {};
\node[coordinate,pin=100:{$\alpha$}]
at (axis cs:1.4,0.1) {};
\node[coordinate,pin=270:{Expected Shortfall}]
at (axis cs:1.6,0) {};
\node[coordinate,pin=86:{Value at Risk}]
at (axis cs:2,0) {};
\end{axis}
\end{tikzpicture}
\end{document}