Graph: absolute vertex size

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.

SeedRandom[42]
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}}]


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.

• 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. – CarbonFlambe Dec 16 '18 at 1:56
• @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) – Szabolcs Dec 16 '18 at 9:05