我想在图表上放置一个坐标tikz
。gnuplot
该怎么做?
我希望图形与小红点重叠,并且我希望这个点稍微大一些。
\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}
答案1
有一种可能性是:
\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}
点附近的放大图像:
答案2
这是一个可能的解决方案,通过从 x 坐标向上绘制intersections
来tikzlibrary
确定交点,然后沿 y 轴水平绘制一条线。
代码
\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}
答案3
您可以简单地在绘图上画线,只需在绘图之前画线即可使线条显示在背景中。此外,您还必须将该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];
这是放大 2400% 后的效果(线条更窄且呈灰色,以匹配轴的刻度)。
并且缩放至 100%。
完整代码:
\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}