How can I set absolute vertex sizes in Graph, so that the vertex size on screen (number of pixels or printer's points) is invariant to changes in the option ImageSize? All of the types of setting in the documentation for VertexSize cause the on-screen size to change with ImageSize.


I do not think that it is possible to do this with VertexSize. The vertex sizes used by Graph are translated to plot coordinates, not to absolute coordinates.

A practical solution is to set a VertexShapeFunction that will ignore the sizes passed to it and renders at a constant absolute size.

g = RandomGraph[{30, 60}]
g = Graph[g, 
       VertexShapeFunction -> Function[{pt, v, size}, Disk[pt, Offset[5]]]];
Table[Show[g, ImageSize -> size], {size, {100, 200, 300}}]

enter image description here

The vertices are always rendered as disks having a radius of 5 pixels, regardless of the image size. You might want to add ImagePadding -> 5 to the above to make sure that there is always enough margin left to render these disks.

  • $\begingroup$ Thanks. But what if I want to use a shape other than Disk? I see in the documentation that Inset will do the trick, but would prefer a cleaner solution. $\endgroup$ – CarbonFlambe Dec 16 '18 at 1:56
  • $\begingroup$ @CarbonFlambe It does not matter what the shape it. As I said, all you need to do is write your own VertexShapeFunction that ignores the size argument and produces something in absolute coordinates (see Offset) $\endgroup$ – Szabolcs Dec 16 '18 at 9:05

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.