我如何标记 x 坐标?

我如何标记 x 坐标?

我为生日悖论做了一个小情节。它看起来像这样: 在此处输入图片描述

这完全没问题,但我想标记 x=23。所以我的问题是:

如何获取以下石灰线? 在此处输入图片描述

这是当前的来源:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning, calc}

\begin{document}
\begin{preview}
\begin{tikzpicture}
    \begin{axis}[
        width=15cm, height=8cm, % size of the image
        grid = major,           
        grid style={dashed, gray!30},
        %xmode=log,log basis x=10,
        %ymode=log,log basis y=10,
        xmin=0,
        xmax=62,
        ymin=0, 
        ymax=1.1,
        /pgfplots/xtick={0,5,...,60},
        extra y ticks={0.507297},
        ylabel=probability of at least one birthday-collision,
        xlabel=people,
         tick align=outside]
      \addplot table [id=exp]{data.csv};
      \addplot[domain=0:23, blue, dashed, thick] {0.507297}; 
      %stirling-formulae
      \addplot[domain=0:60, red, thick] {1-(365/(365-x))^(365.5-x)*e^(-x)}; 
    \end{axis} 
\end{tikzpicture}
\end{preview}
\end{document}

答案1

您可以使用语法访问绘图轴坐标系(axis cs: xcoord,ycoord)。其余的是 TikZ 基础知识。

\documentclass{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning, calc}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        width=15cm, height=8cm, % size of the image
        grid = major,           
        grid style={dashed, gray!30},
        %xmode=log,log basis x=10,
        %ymode=log,log basis y=10,
        xmin=0,
        xmax=62,
        ymin=0, 
        ymax=1.1,
        /pgfplots/xtick={0,5,...,60},
        extra y ticks={0.507297},
        ylabel=probability of at least one birthday-collision,
        xlabel=people,
         tick align=outside]
      %\addplot table [id=exp]{data.csv};
      %stirling-formulae
      \addplot[domain=0:60, red, thick] {1-(365/(365-x))^(365.5-x)*e^(-x)}; 
      \coordinate (a) at (axis cs:23,0.507297);
    \draw[blue,dashed](a -| current plot begin) -- (a);
    \draw[lime,thick](a |- current plot begin) -- (a);
    \end{axis} 
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容