2

How to plot a curve path along nodes in a tikz plot? Just like the image below, the path must be thick and crossing nodes

enter image description here

Here is a MWE; the desired curve should be like the ones in this answer, but drawn over the nodes. The naive \draw plot [smooth] (A) -- (B) -- (C) would draw only a polygonal line connecting them. I have coordinates for all the nodes, but inserting coordinates would be tedious.

\documentclass{article}
\usepackage{siunitx}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage[capposition=top]{floatrow}

\definecolor{nodefill}{RGB}{250,247,196}
\definecolor{linkfill}{RGB}{177,177,151}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}[yscale=0.5, every node/.style={draw=gray,thick,circle,inner sep=-1pt, minimum size=1cm, fill=nodefill}]
    \node[] (A)     at (0.0,-0.2)       {} ;
    \node[] (B)     at (2.0,-1.5)       {} ;
    \node[] (C) at (-0.5,-4.0)      {} ;
    \node[] (D)     at (1.0,-4.3)       {} ;
    \node[] (E)     at (-0.2,-8.0)      {} ;
    \node[] (F)     at (2.4,-7.3)       {} ;

    \draw [draw=linkfill, line width=1.00mm] (A) -- (B) ;
    \draw [draw=linkfill, line width=1.00mm] (A) -- (D) ;
    \draw [draw=linkfill, line width=1.50mm] (B) -- (D) ;
    \draw [draw=linkfill, line width=1.25mm] (B) -- (F) ;
    \draw [draw=linkfill, line width=0.35mm] (C) -- (D) ;
    \draw [draw=linkfill, line width=1.25mm] (D) -- (E) ;
    \draw [draw=linkfill, line width=0.75mm] (E) -- (F) ;
    \draw [draw=linkfill, line width=1.25mm] (D) -- (F) ;

    \end{tikzpicture}
\end{figure}    


\end{document}
3

You can use two ways:

\draw [blue, line width=2pt, double, rounded corners=9pt, ->] (A.center) -- (B.center) -- (C.center) -- (D.center) -- (E.center);
\draw [red, line width=2pt, double, ->] plot[smooth, tension=2] coordinates {(A.center) (D.center) (B.center) (E.center) (F.center)};

linked nodes

The trick is that (A) is a node, while (A.center) is a coordinate.

As suggested by a friendly cat, you can make it more beautiful and simplify the plot syntax; you add

\usetikzlibrary{arrows.meta}

in the preamble and then

\draw [blue, line cap=round, line width=2pt, double, rounded corners=9pt, -Implies] 
    (A.center) -- (B.center) -- (C.center) -- (D.center) -- (E.center);
\draw [red, line cap=round, line width=2pt, double, -{Implies}] 
    plot[smooth,  tension=2] coordinates {(A.center) (D.center) (B.center) 
    (E.center) (F.center)};
\draw [green!50!black, line cap=round, line width=2pt, double, -{Implies}] 
    plot[smooth, tension=2, samples at={A,...,E,B,F},] (\x.center);

enter image description here

| improve this answer | |
  • 2
    +1 You could also add an arrow head from arrows.meta to have an outlined arrow, and add some nice line cap. (And the plot can be done using ‘samples at={A,...,F}’ and ‘(\x.center)’.) – Schrödinger's cat Mar 8 at 19:20
  • @Schrödinger'scat thanks! I tried with the samples at trick but didn't manage it... ;-). The lines are effectively nicer with line cap=round, -{Implies}. – Rmano Mar 8 at 19:39
  • 2
    @Schrödinger'scat yes but forgot to drop the {} enclosing (\x.center).... ;-) – Rmano Mar 8 at 20:05
  • To a cat this looks very familiar, see the title page of this presentation. Do squirrels also like to play with yarn? ;-) – Schrödinger's cat Mar 8 at 22:11
  • @Schrödinger'scat if you wind them around acorns... :-) – Rmano Mar 8 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.