2
$\begingroup$

I have a list of edges defined based on vertices like this:

Edges={{2, 1}, {10, 9}, {11, 10}, {11, 4}, {17, 12},.....} 
(*Where each number is the index of a vertex which has 3D coordinates*)

In order to plot a graph I first made Edges looks like this (I want to plot undirected graph)

edges = Flatten[Table[{Edges[[i, 1]] <-> Edges[[i, 2]]}, {i, 1, Length[Edges]}]];

Then I plot the graph

GraphPlot3D[edges, VertexLabeling -> False, (*VertexCoordinateRules -> nodescoord*), \BoxRatios -> Automatic,ViewPoint -> {0, 0, -Infinity}];

Where am I wrong? Is it the way I define edges using "<->"?

$\endgroup$

2 Answers 2

2
$\begingroup$

Use Graph[] instead of GraphPlot[]

n = 8;
vC = RandomReal[{0, 1}, {n, 3}];
edges = UndirectedEdge @@@ Subsets[Range@n, {2}];
Graph[edges, VertexCoordinates -> vC]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ @ belisarius,Thanks, I thought graph can only display 2D images. But why VertexLabels -> "Name" property fails. And, is there a place to share mine and use Mathematica extension packages written by others? $\endgroup$
    – novice
    Commented Dec 23, 2013 at 5:58
  • $\begingroup$ @novice You can talk about that in chat chat.stackexchange.com $\endgroup$ Commented Dec 23, 2013 at 6:16
0
$\begingroup$

Is it the way I define edges using "<->"?

Yes. If we use -> (Rule) instead of <-> ,GraphPlot3D works as expected.

SeedRandom[123]
n = 20;
edges = RandomChoice[Subsets[Range@n, {2}], 20];
edgelist = Rule @@@ edges;
coords = RandomReal[{0, 1}, {n, 3}];
GraphPlot3D[edgelist, 
 VertexCoordinateRules -> Thread[Range[n] -> coords], Boxed -> False, 
 ImageSize -> 600, EdgeRenderingFunction -> (Tube[#1, .02] &), 
 ViewPoint -> {0, 0, -Infinity}, 
 VertexRenderingFunction ->
  ({ColorData["Atoms"][RandomInteger[{1, 117}]], Sphere[#1, .04]} &), 
 PlotStyle -> Directive[Specularity[White, 20]]] 

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.