1

I am trying to create in Latex a graph with a very large number of edges. Something similar to the attached image (taken from a paper by Bissyandé et al).

I've tried to simply draw a graph using tikzpicture and some of the edges, but how can I import the edges from an external file (CSV?!) and how to change the thickness of the edges based on a value?

Here's the starting point I've done till now:

\begin{tikzpicture}
    \begin{pgfonlayer}{nodelayer}
        \node [style=none] (0) at (-1.25, 4.5) {C};
        \node [style=none] (1) at (3.5, 4.5) {C++};
        \node [style=none] (2) at (3.5, 2.5) {HTML};
        \node [style=none] (3) at (-2.75, 2.5) {JavaScript};
        \node [style=none] (4) at (1.25, 5) {Python};
        \node [style=none] (5) at (1.25, 1.75) {CSS};
        \node [style=none] (6) at (3.75, 6) {Shell};
        \node [style=none] (7) at (-2.25, 5.75) {Objective-C};
        \node [style=none] (8) at (1.75, -0.5) {PHP};
        \node [style=none] (9) at (5, 0) {Java};
        \node [style=none] (10) at (5.25, 3.5) {Makefile};
        \node [style=none] (11) at (-1.75, 0) {Ruby};
    \end{pgfonlayer}
    \begin{pgfonlayer}{edgelayer}
        \draw (0.center) to (3.center);
        \draw (0.center) to (2.center);
        \draw (2.center) to (1.center);
        \draw (3.center) to (1.center);
        \draw (11.center) to (5.center);
        \draw (11.center) to (3.center);
        \draw (11.center) to (0.center);
        \draw (8.center) to (0.center);
        \draw (7.center) to (0.center);
        \draw (4.center) to (5.center);
        \draw (0.center) to (4.center);
        \draw (4.center) to (1.center);
        \draw (6.center) to (10.center);
        \draw (10.center) to (9.center);
        \draw (9.center) to (2.center);
        \draw (2.center) to (10.center);
        \draw (8.center) to (5.center);
        \draw (8.center) to (2.center);
    \end{pgfonlayer}
\end{tikzpicture}

Thanks!

enter image description here

2
  • So? What did you try so far? Show some code!
    – DG'
    Commented Nov 19, 2021 at 12:36
  • @DG' - I have edited the question. Thanks!
    – TCS
    Commented Nov 19, 2021 at 12:51

1 Answer 1

1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-network}
\begin{filecontents}{vertices.csv}
id, x, y ,label
0, -1.25, 4.5, C
1, 3.5, 4.5, C++
2, 3.5, 2.5, HTML
3, -2.75, 2.5, JavaScript
4, 1.25, 5, Python
5, 1.25, 1.75, CSS
6, 3.75, 6, Shell
7, -2.25, 5.75, Objective-C
8, 1.75, -0.5, PHP
9, 5, 0, Java
10, 5.25, 3.5, Makefile
11, -1.75, 0, Ruby
\end{filecontents}
\begin{filecontents}{edges.csv}
u, v, lw
0, 3, 1
0, 2, 2
2, 1, 1
3, 1, 5
11, 5, 1
11, 3, 10
11, 0, 1
8, 0, 1
7, 0, 1
4, 5, 8
0, 4, 1
4, 1, 1
6, 10, 1
10, 9, 3
9, 2, 1
2, 10, 1
8, 5, 1
8, 2, 1
\end{filecontents}
\begin{document}
\begin{tikzpicture}
  \Vertices[size=0, style={inner sep=0pt}]{vertices.csv}
  \Edges[color=lightgray]{edges.csv}
\end{tikzpicture}
\end{document}

Network graph with labels and edges

2
  • Exactly what I was looking for! Thanks!
    – TCS
    Commented Nov 19, 2021 at 17:57
  • 1
    You can also use \Edges[color=gray, opacity=0.5]{edges.csv} to visualise edge crossings as in your image. Commented Nov 19, 2021 at 18:04

You must log in to answer this question.

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