现在我从下面的代码中得到了图 1。我想得到图 2(添加标签)。如何在 tikz 中添加这些内容?
图1
图 2
图 1 的代码
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\def\cdf(#1)(#2)(#3){0.5*(1+(erf((#1-#2)/(#3*sqrt(2)))))}
\DeclareMathOperator{\CDF}{cdf}
\begin{document}
\begin{tikzpicture}[thick,font=\footnotesize]
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
xlabel={Value of $D$},
ylabel={Cumulative Distribution Function}]
\addplot[dashed, domain=-6:1.16]{0.2};
\addplot[dashed, smooth] coordinates {(1.16,0)(1.16,0.2)};
\addplot[dashed, smooth] coordinates {(-0.84,0)(-0.84,0.55)};
\addplot[<->, domain=-0.84:1.16]{0.1};
\addplot[dashdotted, domain=-6:1.75]{0.4};
\addplot[dashdotted] coordinates {(1.75,0)(1.75,0.55)};
\addplot[dashdotted] coordinates {(-0.25,0)(-0.25,0.4)};
\addplot[<->, domain=-0.25:1.75]{0.3};
\addplot[<->, domain=-0.84:1.75]{0.5};
\addplot[smooth,red] gnuplot{\cdf(x)(-2)(1)};
\addplot[smooth,blue]gnuplot{\cdf(x)(0)(1)};
\addplot[smooth,orange]gnuplot{\cdf(x)(2)(1)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这实际上非常简单,只需沿着所需路径添加节点:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\def\cdf(#1)(#2)(#3){0.5*(1+(erf((#1-#2)/(#3*sqrt(2)))))}
\begin{document}
\begin{tikzpicture}[thick,font=\footnotesize]
\begin{axis}[
ticks=none,
axis x line=bottom,
axis y line=left,
clip=false,
xlabel={Value of $D$},
ylabel={Cumulative Distribution Function}]
\addplot[dashed, domain=-6:1.16]{0.2} node [pos=0,left] {$q$};
\addplot[dashed, smooth] coordinates {(1.16,0.2)(1.16,0.0)};
\addplot[dashed, smooth] coordinates {(-0.84,0)(-0.84,0.55)};
\addplot[<->, domain=-0.84:1.16]{0.1} node [midway, above] {$\Delta_1$};
\addplot[dashdotted, domain=-6:1.75]{0.4} node [pos=0,left] {$q^\prime$};
\addplot[dashdotted] coordinates {(1.75,0)(1.75,0.55)};
\addplot[dashdotted] coordinates {(-0.25,0)(-0.25,0.4)};
\addplot[<->, domain=-0.25:1.75]{0.3} node [midway, above] {$\Delta_2$};
\addplot[<->, domain=-0.84:1.75]{0.5} node [midway, above] {$\Delta_3$};
\addplot[smooth,red] gnuplot{\cdf(x)(-2)(1)};
\addplot[smooth,blue]gnuplot{\cdf(x)(0)(1)};
\addplot[smooth,orange]gnuplot{\cdf(x)(2)(1)};
\end{axis}
\end{tikzpicture}
\end{document}
请注意,需要clip=false
允许显示 y 轴上的节点。如果有任何不清楚的地方,请随时在评论中提问。