3

I want to place a coordinate on my tikz/gnuplot graph. How to do this?

coordinateingraph

Preferrably I want the graph to overlap the little red dot, and I'd like the dot slightly larger.

\documentclass{article}

\usepackage{pgfplots}
\usepackage[heightrounded]{geometry}
\usepackage[miktex]{gnuplottex}

\begin{document}

\subsubsection{P-waarde bij de chi-kwadraattoets}

\textbf{\textit{Let op!}} Deze paragraaf is geen stof die je moet weten, maar alleen ter verduidelijking!

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}
  \begin{axis}[%
    xlabel = $\chi ^2$,
    ylabel = $P\left(\chi ^2 (5) \geq \chi ^2\right)$,
    samples = 200,
   xtick={4,5,6,...,15},ytick={0,.05,.1,.15,.2,.25,.3,.35,.4,.45,.5},
    restrict y to domain = 0.045:0.5,
    domain = 5:15,
  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=8cm, width=8cm,
axis lines*=left]
    \foreach \k in {5} {%
      \addplot+[mark={}] gnuplot[raw gnuplot] {%
    isint(x)=(int(x)==x);
    log2 = 0.693147180559945;
    cchisq(x,k)=k<=0||!isint(k)?1/0:x<0?0.0:igamma(0.5*k,0.5*x);
    set xrange [ 5 : 15.0000 ];
    set yrange [ 0 : 1.0000 ];
        samples=200;
        plot 1-cchisq(x,\k)};
}
  \end{axis}
\end{tikzpicture}
\end{center}
\caption{Kansfunctie (Chi-kwadraat CDF) om een bepaalde waarde van $\chi ^2$ te vinden}
\end{figure}
\end{document}
1010011010
  • 6,357

3 Answers3

3

Here's one possibility:

\documentclass{article}
\usepackage[heightrounded]{geometry}
\usepackage{pgfplots}
\usepackage[miktex]{gnuplottex}
\usetikzlibrary{intersections,backgrounds}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{document}

\subsubsection{P-waarde bij de chi-kwadraattoets}

\textbf{\textit{Let op!}} Deze paragraaf is geen stof die je moet weten, maar alleen ter verduidelijking!

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
  xlabel = $\chi ^2$,
  ylabel = $P\left(\chi ^2 (5) \geq \chi ^2\right)$,
  samples = 200,
  xtick={4,5,6,...,15},
  ytick={0,.05,.1,.15,.2,.25,.3,.35,.4,.45,.5},
  restrict y to domain = 0.045:0.5,
  domain = 5:15,
  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=8cm, 
  width=8cm,
  axis lines*=left
  ]
  % a vertical ``invisible'' line to get the coordinates of the dot
  \path[name path=line] (axis cs:2.5,0) -- (axis cs:2.5,0.5);
  \foreach \k in {5} {%
    \addplot+[mark={},name path=graph] gnuplot[raw gnuplot] {%
      isint(x)=(int(x)==x);
      log2 = 0.693147180559945;
      cchisq(x,k)=k<=0||!isint(k)?1/0:x<0?0.0:igamma(0.5*k,0.5*x);
      set xrange [ 5 : 15.0000 ];
      set yrange [ 0 : 1.0000 ];
      samples=200;
      plot 1-cchisq(x,\k)};
  }
  % we get the coordinates of the intersection of the graph and the invisible line
  % the resulting point is called interp
  \path[name intersections={of=line and graph, by={interp}}];
  % we place the dot behind the graph
  \begin{pgfonlayer}{background}
    \node[draw=red,circle,inner sep=1.7pt] at (interp) {};
  \end{pgfonlayer}
  % we draw the lines connecting the dot with the axes 
  \draw (axis cs:2.5,0) -- (interp);
  \draw (interp) -- ({axis cs:0,0}|-interp);
  \end{axis}
\end{tikzpicture}
\caption{Kansfunctie (Chi-kwadraat CDF) om een bepaalde waarde van $\chi ^2$ te vinden}
\end{figure}

\end{document}

enter image description here

A zoomed image of the vicinity of the dot:

enter image description here

Gonzalo Medina
  • 505,128
2

This a possible solution where intersections from tikzlibrary is used to determine the intersection point by drawing up from an x coordinate, then draw a line horizontally to y axis.

enter image description here

Code

\documentclass{article}
\usepackage[margin=0.5cm,papersize={12cm,14cm}]{geometry}
\usepackage{pgfplots}
\usepackage[heightrounded]{geometry}
\usepackage[miktex]{gnuplottex}
\usetikzlibrary{intersections}

\begin{document}

\newcommand*{\ShowIntersection}[2]{ % borrowed from http://tex.stackexchange.com/a/21409/34618
\fill
    [name intersections={of=#1 and #2, name=i, total=\t}]
    [red, opacity=1, every node/.style={above left, black, opacity=1}]
    \foreach \s in {1,...,\t}{(i-\s) circle (2pt)};
}

\subsubsection{P-waarde bij de chi-kwadraattoets}

\textbf{\textit{Let op!}} Deze paragraaf is geen stof die je moet weten, maar alleen ter verduidelijking!

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}
  \begin{axis}[%
    xlabel = $\chi ^2$,
    ylabel = $P\left(\chi ^2 (5) \geq \chi ^2\right)$,
    samples = 200,
   xtick={4,5,6,...,15},ytick={0,.05,.1,.15,.2,.25,.3,.35,.4,.45,.5},
    restrict y to domain = 0.045:0.5,
    domain = 5:15,
  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=8cm, width=8cm,
axis lines*=left]
    \foreach \k in {5} {%
      \addplot+[mark={},name path global=a] gnuplot[raw gnuplot] {%
    isint(x)=(int(x)==x);
    log2 = 0.693147180559945;
    cchisq(x,k)=k<=0||!isint(k)?1/0:x<0?0.0:igamma(0.5*k,0.5*x);
    set xrange [ 5 : 15.0000 ];
    set yrange [ 0 : 1.0000 ];
        samples=200;
        plot 1-cchisq(x,\k)};
}
\draw [red,name path global=b] (axis cs: 5.8,0)--(axis cs: 5.8,0.35);  % draw a line to find intersection
\ShowIntersection{a}{b}                                                % show intersection
\draw [red] (i-1) -| (axis cs: 0,1);                                   % draw a line from intersection point to y axis
  \end{axis}
\end{tikzpicture}
\end{center}
\caption{Kansfunctie (Chi-kwadraat CDF) om een bepaalde waarde van $\chi ^2$ te vinden}
\end{figure}
\end{document}
Jesse
  • 29,686
0

You can simply draw lines on your plot, you only have to draw the lines before plotting to make the lines appear in the background. Also you will have to include the axis on top=true option into the axis options.

\draw[gray, line width=0.2pt] (axis cs:5.6655,0) -- (axis cs:5.6655,0.34) -- (axis cs:0,0.34);
\draw[red] (axis cs:5.6655,0.34) circle[radius=2pt];

Here is what it looks like at 2400% zoom (the lines are narrower and gray to match the ticks of the axis).

And at 100% zoom.

Full code:

\documentclass{article}

\usepackage{pgfplots}
\usepackage[heightrounded]{geometry}
\usepackage[miktex]{gnuplottex}

\begin{document}

\subsubsection{P-waarde bij de chi-kwadraattoets}

\textbf{\textit{Let op!}} Deze paragraaf is geen stof die je moet weten, maar alleen ter verduidelijking!

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}
    \begin{axis}[%
        xlabel = $\chi ^2$,
        ylabel = $P\left(\chi ^2 (5) \geq \chi ^2\right)$,
        samples = 200,
        xtick={4,5,6,...,15},ytick={0,.05,.1,.15,.2,.25,.3,.35,.4,.45,.5},
        restrict y to domain = 0.045:0.5,
        domain = 5:15,
        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=8cm, width=8cm,
        axis lines*=left,
        axis on top=true]
            \draw[gray, line width=0.2pt] (axis cs:5.6655,0) -- (axis cs:5.6655,0.34) -- (axis cs:0,0.34);
            \draw[red] (axis cs:5.6655,0.34) circle[radius=2pt];
            \foreach \k in {5} {%
                \addplot+[mark={}] gnuplot[raw gnuplot] {%
                    isint(x)=(int(x)==x);
                    log2 = 0.693147180559945;
                    cchisq(x,k)=k<=0||!isint(k)?1/0:x<0?0.0:igamma(0.5*k,0.5*x);
                    set xrange [ 5 : 15.0000 ];
                    set yrange [ 0 : 1.0000 ];
                    samples=200;
                    plot 1-cchisq(x,\k)
                };
            }
    \end{axis}
\end{tikzpicture}
\end{center}
\caption{Kansfunctie (Chi-kwadraat CDF) om een bepaalde waarde van $\chi ^2$ te vinden}
\end{figure}
\end{document}
szantaii
  • 4,719
  • 2
  • 36
  • 51