I would like to put a radial gradient effect on the nodes of a network. As far as I can tell Mathematica does not support radial gradient fill effects for graphics primitives. One way to get the radial gradient effect is with concentric circles, and a few other alternatives that I've found around the net. I made my own version using a triangular polygon that is rotated and it tends to give smoother gradients at the expense of ragged edges, but those are transparent for these applications so it works nicely.
Unfortunately, I can't get the graphics object to scale at all, and it's supposed to scale by the radius property. Also, the only way I could figure out how to get the nodes to be the shapes is to set the VertexShapeFunction
for each node separately using Properties
. In the sample below I've only done this for the second node, but I could build a table of these if that's the only way to set it.
TheGraph=RandomGraph[{5, 8}];
TheNodeColors={Red,Green,Blue,Purple,Orange};
TheNodeSizes={1,2,3,4,5};
GradientFillNode[theColor_:grey,theRadius_:1,NumberOfSlices_:40]:=Graphics[Table[Polygon[{{0,0},{theRadius*Cos[2Pi t/NumberOfSlices],theRadius*Sin[2Pi t/NumberOfSlices]},{theRadius*Cos[2Pi (t+1)/NumberOfSlices],theRadius*Sin[2Pi (t+1)/NumberOfSlices]}},VertexColors->{theColor,Opacity[0,theColor],Opacity[0,theColor]}],{t,NumberOfSlices}]];
NodeImages=Table[GradientFillNode[TheNodeColors[[i]],TheNodeSizes[[i]],40],{i,Length[TheNodeColors]}]
ColoredGraph=Graph[TheGraph,VertexShapeFunction->(Inset[NodeImages[[1]],#]&),ImageSize->500,Properties->{2->{VertexShapeFunction->(Inset[NodeImages[[2]],#]&)}}]
As you can see if you run it, this does change the color of the second node, but the sizes are all the same.
(1) How do I get the nodes to size according to my setting?
(2) Is there a better way to use the VertexShapeFunction
to have it color and size the nodes properly?
(3) Is there an entirely different and better way to achieve nodes with a radial color gradient?