Creating a network with coordinate and link data

Here is a solution that mixes csvsimple and tikz to generate the network. The answer from @ Schrödinger's cat is more efficient but it shows how to use the csvsimple capabilities to read Tikz data files and drawing capabilities.

To make the plot, I simplified initial data (deletion of zeros) and added a comma separator.

% !TeX encoding = utf8
% !TeX spellcheck = fr
\documentclass{article}
\usepackage{csvsimple}
\usepackage{tikz}
\usetikzlibrary{calc}


\usepackage{filecontents}
\begin{filecontents*}{data2.csv}
Node,X,Y
1,5,51
2,32,51
3,5,44
4,13,44
5,22,44
6,32,44
7,42,38
8,32,38
9,22,38
10,22,32
11,13,32
12,5,32
13,5,5
14,13,19
15,22,19
16,32,32
17,32,26
18,42,32
19,32,19
20,32,5
21,22,5
22,22,13
23,13,13
24,13,5
\end{filecontents*}


\begin{filecontents*}{fromTo.csv}
fromNode, toNode
1,2
1,3
2,1
2,6
3,1
3,4
3,12
4,3
4,5
4,11
5,4
5,6
5,9
6,2
6,5
6,8
7,8
7,18
8,6
8,7
8,9
8,16
9,5
9,8
9,10
10,9
10,11
10,15
10,16
10,17
11,4
11,10
11,12
11,14
12,3
12,11
12,13
13,12
13,24
14,11
14,15
14,23
15,10
15,14
15,19
15,22
16,8
16,10
16,17
16,18
17,10
17,16
17,19
18,7
18,16
18,20
19,15
19,17
19,20
20,18
20,19
20,21
20,22
21,20
21,22
21,24
22,15
22,20
22,21
22,23
23,14
23,22
23,24
24,13
24,21
24,23
\end{filecontents*}

\begin{document}
\begin{tikzpicture}[scale=0.3]
    \csvreader[head to column names]{data2.csv}{}
    {
    \node[draw,circle](N\Node) at (\X,\Y){\Node}; 
    }
    \csvreader[head to column names]{fromTo.csv}{}
    {
    \draw(N\fromNode) -- (N\toNode);
    }
\end{tikzpicture}
\end{document}

enter image description here


You could use tikz-network here.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{vert.csv}
id, label, x, y
1,,5,51
2,,32,51
3,,5,44
4,,13,44
5,,22,44
6,,32,44
7,,42,38
8,,32,38
9,,22,38
10,,22,32
11,,13,32
12,,5,32
13,,5,5
14,,13,19
15,,22,19
16,,32,32
17,,32,26
18,,42,32
19,,32,19
20,,32,5
21,,22,5
22,,22,13
23,,13,13
24,,13,5
\end{filecontents*}
\begin{filecontents*}{edg.csv}
u,v
1,2
1,3
2,1
2,6
3,1
3,4
3,12
4,3
4,5
4,11
5,4
5,6
5,9
6,2
6,5
6,8
7,8
7,18
8,6
8,7
8,9
8,16
9,5
9,8
9,10
10,9
10,11
10,15
10,16
10,17
11,4
11,10
11,12
11,14
12,3
12,11
12,13
13,12
13,24
14,11
14,15
14,23
15,10
15,14
15,19
15,22
16,8
16,10
16,17
16,18
17,10
17,16
17,19
18,7
18,16
18,20
19,15
19,17
19,20
20,18
20,19
20,21
20,22
21,20
21,22
21,24
22,15
22,20
22,21
22,23
23,14
23,22
23,24
24,13
24,21
24,23
\end{filecontents*}

\usepackage{tikz-network}
\begin{document}
\begin{tikzpicture}[scale=0.2]
\SetVertexStyle[MinSize=0.2cm]
\Vertices{vert.csv}
\Edges{edg.csv}
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Draw

Tikz Pgf