在我的图表中,箭头点(圆圈)的位置不太好,我知道箭头点接触函数值,但由于我使用圆圈来表示函数中的点。我如何“强制”箭头中心结束在值而不是点上?
妇女权利委员会:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows,positioning,calc}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\begin{tikzpicture}[samples=101,domain=-1:1,xscale=3]
\draw[->] (-1.2,0) -- (1.3,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$u(x)$};
\draw[color=blue] plot (\x,{sin(2 * pi * \x r))}) node[above right] {};
\foreach \i [evaluate=\i as \j using {(\i-4)/4}] in {0, 1, ..., 8} {
\pgfmathsetmacro\s{sin(2*pi * \j r)};
\draw[thin,o-] (\j,\s) -- (\j,0) node[below left,rotate=45] {$x_\i$};
}
\draw [|-|] (0.5,1) -- (0.75,1) node[midway,fill=white] {$h$};
\end{tikzpicture}
\end{figure}
\end{document}
PS:当然,我们也欢迎对图表/代码可读性进行任何其他改进
答案1
xscale
我没有使用 ,而是使用了x = 3cm
。此外,这些点被单独绘制为圆圈。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows,positioning,calc}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\begin{tikzpicture}[samples=101,domain=-1:1,x=3cm]
\draw[->] (-1.2,0) -- (1.3,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$u(x)$};
\draw[color=blue] plot (\x,{sin(2 * pi * \x r))}) node[above right] {};
\foreach \i [evaluate=\i as \j using {(\i-4)/4}] in {0, 1, ..., 8} {
\pgfmathsetmacro\s{sin(2*pi * \j r)};
\draw[thin](\j,\s) -- (\j,0) node[below left,rotate=45] {$x_\i$};
\fill[blue] (\j,\s) circle (2pt);
}
\draw [|-|] (0.5,1) -- (0.75,1) node[midway,fill=white] {$h$};
\end{tikzpicture}
\end{figure}
\end{document}