2

In my graph, the arrows points (circles) are not very well placed, I understand that arrow point is touching the function value, but since I'm using circles to represent the points in a function. How can I "force" the arrow center finish over the value instead the point?

The MWE:

\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: Of course any other improvements to graph/code readability are also welcome

2
  • you mean the wave should pass through the center of all the circles? May 7, 2019 at 6:46
  • yes. or the center of the circle should be over the wave.
    – Lin
    May 7, 2019 at 6:53

1 Answer 1

3

Instead of using xscale, I used x = 3cm. Also, the points are drawn separately as circles.

Output

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .