Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Consider the following

testadj = RandomVariate[BernoulliDistribution[0.15], {50, 50}];
AdjacencyGraph[testadj, VertexSize -> Large]

enter image description here

The nodes are almost completely hidden in the mess of edges. They can be made easier to see by making the edges fade into the background a little.

AdjacencyGraph[testadj, EdgeStyle -> Directive[Opacity[0.4], Gray], 
 VertexSize -> Large]

enter image description here

But we still have the problem that the lines draw over the top of the nodes. Is there a way to force the nodes to draw on top of the lines?

share|improve this question
    
I have a feeling this has been asked before, or at least came up in a question. I can't find it unfortunately. –  Szabolcs Jul 26 '12 at 9:11
    
Do you need to keep the graph functionality or would it be enough to create a Graphics (not Graph) object that has the vertices on top? –  Szabolcs Jul 26 '12 at 9:12
    
@Szabolcs This one? stackoverflow.com/a/8205128/353410 –  belisarius Jul 26 '12 at 12:51
    
@belisarius - it's a different problem. –  Verbeia Jul 27 '12 at 0:07
    
@Verbeia Look at Mr's answer :) –  belisarius Jul 27 '12 at 0:11
show 1 more comment

4 Answers

up vote 5 down vote accepted

This is a nasty hack. It might be the quickest workaround until you find a solution.

testadj = RandomVariate[BernoulliDistribution[0.15], {50, 50}];
gr = AdjacencyGraph[testadj, VertexSize -> Large]

Show[gr, SetProperty[gr, EdgeShapeFunction -> ({} &)]]

Mathematica graphics

The end result is a Graphics object, not a Graph. I am using {} as a "neutral graphics object", something that is accepted inside Graphics, but does not render.

Unfortunately the analogous SetProperty[gr, VertexShapeFunction -> ({} &)] does not seem to work, and I don't understand why. It may have to do something with the fact that the system analyses the vertex shape to make the edges join up nicely to them. If you need to make them disappear, you can use SetProperty[gr, VertexShape -> None].

share|improve this answer
add comment

GraphPlot does alright. Perhaps Inset is the key.

testadj = RandomInteger[BernoulliDistribution[0.15], {50, 50}];

(* gr = graphic *)

GraphPlot[testadj, VertexRenderingFunction -> (Inset[gr, #1] &)]

Mathematica graphics

share|improve this answer
1  
I´d go for the Evolution smiley ;-) –  Yves Klett Jul 26 '12 at 9:49
    
Having our Q&A in two different sites makes us repeat ourselves :) stackoverflow.com/questions/885910/… –  belisarius Jul 26 '12 at 15:03
    
This is a similar solution but the problem is actually different. –  Verbeia Jul 27 '12 at 0:07
add comment

Here is my implementation by modifying the Box structures.

Clear[vertexFirstShow]
vertexFirstShow[graph_] :=
    Module[{graphdata, vShow},
           graphdata = ToBoxes[graph];
           vShow = 
                  Cases[graphdata, GraphicsGroupBox[{v_, e_}] :> v, \[Infinity]][[1]]
                       /. {
                           TagBox[DiskBox[pos_, r_], "DynamicName", BoxID -> id_]
                                :> DiskBox[DynamicLocation[id], r],
                           TagBox[StyleBox[DiskBox[pos_, r_], opts__], "DynamicName", BoxID -> id_]
                                :> StyleBox[DiskBox[DynamicLocation[id], r], opts]
                          };
           With[{v2 = vShow},
                ToExpression[
                      graphdata /. GraphicsGroupBox[{v_, e_}] :> GraphicsGroupBox[{v, e, v2}]]
          ]]

testadj = RandomVariate[BernoulliDistribution[0.15], {50, 50}];

graph = AdjacencyGraph[testadj, VertexSize -> Large, GraphHighlight -> {1, 2, 3}]

vertexFirstShow[graph]

enter image description here

It retains a Graph object, and I'm sure the code can be improved to fit more complicated cases.

share|improve this answer
    
Really nice solution, thanks! I accepted @Szabolcs' because it was sufficient for our purposes. –  Verbeia Jul 27 '12 at 0:07
    
@Verbeia His answer is great. It never comes to my mind to use EdgeShapeFunction like that. :) –  Silvia Jul 27 '12 at 0:12
add comment

You can always extract full info from Graph and then use graphics primitives. It is more elaborate but it gives full control.

testadj = RandomVariate[BernoulliDistribution[0.15], {50, 50}];
g = AdjacencyGraph[testadj, VertexSize -> 0];
Show[g, Graphics[{Red, PointSize[Large], 
   Point[AbsoluteOptions[g, VertexCoordinates][[2]]]}]]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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