4

Is it possible to create a network with node coordinate and link data using TikZ or any other package?

The node coordinate data is given below:

Node    X        Y
   1    50000   510000
   2    320000  510000
   3    50000   440000
   4    130000  440000
   5    220000  440000
   6    320000  440000
   7    420000  380000
   8    320000  380000
   9    220000  380000
  10    220000  320000
  11    130000  320000
  12    50000   320000
  13    50000   50000
  14    130000  190000
  15    220000  190000
  16    320000  320000
  17    320000  260000
  18    420000  320000
  19    320000  190000
  20    320000  50000
  21    220000  50000
  22    220000  130000
  23    130000  130000
  24    130000  50000

The link data is given below:

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
  • Welcome! Did you try using the tikz-network package? – user194703 Oct 26 '19 at 17:17
  • Thanks! Schrödinger's cat. I was not aware of this package. – Pramesh Kumar Oct 26 '19 at 17:45
6

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

| improve this answer | |
  • I didn't know about this (+1). – user194703 Oct 27 '19 at 0:55
5

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

| improve this answer | |
  • It works! Thanks so much! – Pramesh Kumar Oct 26 '19 at 17:45

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.