I have a list of pairs of numbers, representing connections between objects in the real world. Each number is the identifier of an object, there are gaps in the range from the smallest number to the largest number.


I need to visualise how all of the objects are related. I intended to create a graph representation of that network.

  • 2
    $\begingroup$ Just curious: Have you tried looking this up in the built-in documentation (F1 on Windows) and if so, what problems did you encounter there? $\endgroup$ – Sjoerd C. de Vries Dec 15 '13 at 22:27

If you have a list

list = {{43, 292}, {22, 11}, {932, 11}, {292, 22}};

Then you can construct a Graph by

Graph[UndirectedEdge @@@ list, VertexLabels -> "Name"] 

enter image description here

| improve this answer | |
  • $\begingroup$ +1, but I wonder how the OP missed the Graph[ ] docs $\endgroup$ – Dr. belisarius Dec 15 '13 at 22:59
  • $\begingroup$ Graph::supp: Mixed graphs and multigraphs are not supported. >> .. I tried eliminate duplicates with list = DeleteDuplicates[list, Equal[#1, #2] &] before executing the command you gave. $\endgroup$ – Pétur Ingi Egilsson Dec 16 '13 at 0:16
  • $\begingroup$ @Pétur Try list = DeleteDuplicates[Sort/@ list, Equal[#1, #2] &] instead $\endgroup$ – Dr. belisarius Dec 16 '13 at 3:57

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.