我似乎找不到一个简单的例子来展示如何控制 tikz 箭头的端点。我看到了很多复杂的例子,我相信也存在简单的例子,但我找不到。如果有好心人能给我指出正确的方向(糟糕的双关语),我将不胜感激。在下面的例子中,我希望双箭头的尖端接触到线条。
\documentclass[11pt,letterpaper]{article}
\usepackage{pgfplots}
\usetikzlibrary{shapes.arrows, fadings}
\pgfmathdeclarefunction{std_norm}{1}{%
\pgfmathparse{1/(sqrt(2*pi))*exp(-((#1)^2)/(2))}%
}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.6]
\begin{axis}[
no markers,
domain=-4:4, % Only display z values between -4 and 4.
samples=100,
xlabel=\textbf{z},
every axis x label/.style={at={(axis description cs:1.0, 0.0)}, anchor=west},
height=5cm, width=12cm,
xtick=\empty, ytick=\empty,
enlargelimits=false,
clip=false,
axis on top=true,
hide y axis,
axis x line*=middle,
axis line style ={thick,latex-latex}
]
\addplot [very thick,draw=cyan!50!black] {std_norm(x)};
\draw [thick] (axis cs:-1.75,0) -- (axis cs:-1.75,{std_norm(-1.75)});
\draw [thick] (axis cs:1.75,0) -- (axis cs:1.75,{std_norm(1.75)});
\draw [thick] (axis cs:-1.75,0.53) -- (axis cs:-1.75,{std_norm(-1.75)+0.03});
\draw [thick] (axis cs:1.75,0.53) -- (axis cs:1.75,{std_norm(1.75)+0.03});
\node [draw=gray,
left color=white,
right color=green!30,
double arrow,
minimum height=4cm,
minimum width=1cm,
double arrow head extend=0.05cm
] at (axis cs:0.0,0.5) {};
\draw node at (axis cs:0, 0.5) {Confidence Interval};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案1
其中一个选项是使用calc
库。这使我们能够使用零件测量节点/坐标之间的距离
let \p1=($(R)-(L)$) in
一般来说距离是,\n1={veclen(\x1,\y1}
但这里的线是水平的,所以只是\x1
。
\documentclass[11pt,letterpaper]{article}
\usepackage{pgfplots}
\usetikzlibrary{shapes.arrows, fadings,calc}
\pgfmathdeclarefunction{std_norm}{1}{%
\pgfmathparse{1/(sqrt(2*pi))*exp(-((#1)^2)/(2))}%
}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.6]
\begin{axis}[
no markers,
domain=-4:4, % Only display z values between -4 and 4.
samples=100,
xlabel=\textbf{z},
every axis x label/.style={at={(axis description cs:1.0, 0.0)}, anchor=west},
height=5cm, width=12cm,
xtick=\empty, ytick=\empty,
enlargelimits=false,
clip=false,
axis on top=true,
hide y axis,
axis x line*=middle,
axis line style ={thick,latex-latex}
]
\addplot [very thick,draw=cyan!50!black] {std_norm(x)};
\draw [thick] (axis cs:-1.75,0) -- (axis cs:-1.75,{std_norm(-1.75)})
coordinate[pos=1] (L);
\draw [thick] (axis cs:1.75,0) -- (axis cs:1.75,{std_norm(1.75)})
coordinate[pos=1] (R);
\draw [thick] (axis cs:-1.75,0.53) -- (axis cs:-1.75,{std_norm(-1.75)+0.03});
\draw [thick] (axis cs:1.75,0.53) -- (axis cs:1.75,{std_norm(1.75)+0.03});
\path let \p1=($(R)-(L)$) in (axis cs:0, 0.5)
node [draw=gray,
left color=white,
right color=green!30,
double arrow,
minimum height=\x1,
minimum width=1cm,
double arrow head extend=0.05cm,inner xsep=0pt
] {Confidence Interval};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
其他值得尝试的选项是使用fit
。