2

Here it is: I want to draw a big graph, say 50 vertices and ~200 edges. I'm getting the edges from the output of GAP, a programme for computational algebra. As it is, I have no idea what the graph will look like, but I can ask the programme to print pairs of integers or whatever. For instance:

1 -- 2,
1 -- 3,
1 -- 31,
1 -- 32,
1 -- 33,
1 -- 34,
1 -- 35,
1 -- 36,
1 -- 37,
1 -- 38,
1 -- 39,
1 -- 40,
1 -- 41,
1 -- 42,
2 -- 3,
2 -- 31,
2 -- 32,
2 -- 33,
2 -- 34,
2 -- 35,
2 -- 36,
2 -- 37,
2 -- 38,
2 -- 39,
2 -- 40,
2 -- 41,
2 -- 42,
3 -- 31,
3 -- 32,
3 -- 33,
3 -- 34,
3 -- 35,
3 -- 36,
3 -- 37,
3 -- 38,
3 -- 39,
3 -- 40,
3 -- 41,
3 -- 42,
4 -- 6,
4 -- 9,
4 -- 37,
4 -- 38,
4 -- 39,
5 -- 8,
5 -- 11,
5 -- 37,
5 -- 38,
5 -- 39,
6 -- 9,
6 -- 37,
6 -- 38,
6 -- 39,
7 -- 10,
7 -- 12,
7 -- 37,
7 -- 38,
7 -- 39,
8 -- 11,
8 -- 37,
8 -- 38,
8 -- 39,
9 -- 37,
9 -- 38,
9 -- 39,
10 -- 12,
10 -- 37,
10 -- 38,
10 -- 39,
11 -- 37,
11 -- 38,
11 -- 39,
12 -- 37,
12 -- 38,
12 -- 39,
13 -- 15,
13 -- 18,
13 -- 34,
13 -- 35,
13 -- 36,
14 -- 17,
14 -- 20,
14 -- 34,
14 -- 35,
14 -- 36,
15 -- 18,
15 -- 34,
15 -- 35,
15 -- 36,
16 -- 19,
16 -- 21,
16 -- 34,
16 -- 35,
16 -- 36,
17 -- 20,
17 -- 34,
17 -- 35,
17 -- 36,
18 -- 34,
18 -- 35,
18 -- 36,
19 -- 21,
19 -- 34,
19 -- 35,
19 -- 36,
20 -- 34,
20 -- 35,
20 -- 36,
21 -- 34,
21 -- 35,
21 -- 36,
22 -- 24,
22 -- 27,
22 -- 40,
22 -- 41,
22 -- 42,
23 -- 26,
23 -- 29,
23 -- 40,
23 -- 41,
23 -- 42,
24 -- 27,
24 -- 40,
24 -- 41,
24 -- 42,
25 -- 28,
25 -- 30,
25 -- 40,
25 -- 41,
25 -- 42,
26 -- 29,
26 -- 40,
26 -- 41,
26 -- 42,
27 -- 40,
27 -- 41,
27 -- 42,
28 -- 30,
28 -- 40,
28 -- 41,
28 -- 42,
29 -- 40,
29 -- 41,
29 -- 42,
30 -- 40,
30 -- 41,
30 -- 42,
31 -- 32,
31 -- 33,
32 -- 33,
34 -- 35,
34 -- 36,
35 -- 36,
37 -- 38,
37 -- 39,
38 -- 39,
40 -- 41,
40 -- 42,
41 -- 42,

and I want to create a graph (in the combinatorial sense) having vertices 1,2,... and edges drawn according to the pairs printed. Since I'll be getting a huge list, is there some method that will allow me to automatically enter this list with copy-paste into some code and have the graph drawn for me? I can obviously change what GAP prints, e.g. if instead of 1 2 we need (1,2) or some other string with relevant information.

I have zero knowledge of tikz.

Update: using the code suggested, I get the following graph:

enter image description here

Any suggestions how to better draw this graph would be welcome (the messy one in the middle is the complete graph on 6 vertices).

11
  • If you can cook up a small (but still realistic) example dataset we can fiddle with it but this is not a math site so what you mean by graph is not so familiar to (some of) us. Paint drawings are also more than welcome ;)
    – percusse
    Feb 17, 2015 at 22:10
  • The meaning of the word graph is the same as Petersen graph, for instance, although I don't know if mine will end up looking regular like the Petersen graph.
    – the_fox
    Feb 17, 2015 at 22:22
  • 1
    Sage includes GAP and has various algorithms for drawing graphs which can be used by sagetex. I have mentioned some of this (drawing Petersen's graph) in my answer to this question.
    – DJP
    Feb 17, 2015 at 22:23
  • I need time to look carefully at your answer there, but just a quick question: can sage (or sage.tex) automatically deduce from the data what the connected components are and draw them "separately" in some sense (but still as one graph)?
    – the_fox
    Feb 17, 2015 at 22:32
  • 1
    Finding a good (i.e. useful for humans) visual representation of a large unknown graph is a hard problem. You might want to consider using a visualization tool as a preliminary step, so you have an idea of what you want. Perhaps gephi (gephi.github.io) or something like it. (I don't know that particular one - just found it with google.) Feb 18, 2015 at 14:13

1 Answer 1

5
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{force}

\begin{document}
\tikz [rounded corners]
\graph [spring layout, node distance=2cm]
{
1 -- 2,
1 -- 3,
1 -- 31,
1 -- 32,
1 -- 33,
2 -- 3,
32 -- 33,
33 -- 31
};

\end{document}

Needs to be compiled with LuaLaTeX. More details on PGF manual, page 369 and 421.

enter image description here

6
  • Cheers. So I should ask that the output be printed in the form a -- b,
    – the_fox
    Feb 17, 2015 at 22:37
  • My tex editor (latexian) says "I can't find file tikzlibrarygraphdrawing. Is this common?
    – the_fox
    Feb 17, 2015 at 22:46
  • Are you using TeXlive or MikTeX?
    – Astrinus
    Feb 17, 2015 at 22:48
  • I am using TeXlive.
    – the_fox
    Feb 17, 2015 at 22:52
  • On my system compiles fine... but I'm using the latest TeXlive. Try to update.
    – Astrinus
    Feb 17, 2015 at 23:09

You must log in to answer this question.

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