For this question, g is a Graph object (of order ~2K) such that the VertexWeight and EdgeWeight properties are defined for every vertex and edge, respectively, and have values in the unit interval1.

I want to implement custom functions to set g's VertexShapeFunction and EdgeShapeFunction properties to. I want these functions to have this form:

(* for VertexShapeFunction *)
If[PropertyValue[{g, #2}, VertexWeight] < cutoff,
   defaultVertex[##]] &

(* for EdgeShapeFunction *)
If[PropertyValue[{g, #2}, EdgeWeight] < cutoff,
   defaultEdge[##]] &

(The symbol cutoff represents an external parameter that I intend to modify repeatedly to affect how the graph is displayed. The intent is that as one lowers the value of cutoff, more vertices and edges will become visible. The positions of vertices and edges should never change as one varies cutoff.)

By dumb (and lengthy) trial-and-error, I've found that setting

invisibleVertex = Directive[Opacity[0], EdgeForm[None]];
invisibleEdge = {};

produces adequate results (although these settings are literally clueless, and I welcome more informed alternatives).

I have not found anything remotely adequate to put in the locations indicated by the placeholders defaultVertex[##] and defaultEdge[##] above.

Is there a way to do what I'm trying to do?

Also, FWIW, for each vertex, the value of its VertexWeight property is the maximum of the EdgeWeight property of all the edges incident upon it, or -1 if there are no such edges.


1 Answer 1


HighlightGraph combined with Style may be a good alternative:

g1 = CompleteGraph[10, EdgeWeight -> eweights, 
   VertexWeight -> vweights, ImageSize -> 300,
   VertexShapeFunction -> "Star", VertexSize -> .3, 
   VertexStyle -> Orange, EdgeShapeFunction -> "FilledArcArrow", 
   EdgeStyle -> Directive[{Blue, Thick}]];

enter image description here

vweights = RandomReal[1, {VertexCount[g1]}];
eweights = RandomReal[1, {EdgeCount[g1]}];
cutoff = .5;
sv = Select[VertexList[g1], PropertyValue[{g1, #}, VertexWeight] < cutoff &];
se = Select[EdgeList[g1], PropertyValue[{g1, #}, EdgeWeight] < cutoff &];

g2 = HighlightGraph[g1, Style[#, Opacity[0.], Thickness[0.], EdgeForm[]] & /@  Join[sv, se]];

Row[{g1, g2}, Spacer[5]]

enter image description here


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.