Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I made a little plot for the birthday paradox. It looks like this: enter image description here

This is perfectly fine, but I would like to mark x=23. So my question is:

How do I get the following lime line? enter image description here

This is the current source:

\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}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You can access the plot axis coordinate system with (axis cs: xcoord,ycoord) syntax. The rest is TikZ basics.

\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}

enter image description here

share|improve this answer
    
Is the small "bump" at x=15 correct? –  Jellby Jul 23 '12 at 11:25
    
@Jellby I think it's just numerical noise. Add samples=500 option to the addplot and it would be more apparent. fpu library would be more suitable for these numbers that are close to zero. –  percusse Jul 23 '12 at 11:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.