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.
If the graph is directed, it is important to add
PerformanceGoal -> "Quality"
so that arrowheads will be positioned correctly.
Unfortunately, the technique above will often lead to parts of the vertices being cut off at the image borders. The ImagePadding
must be increased manually to prevent this.
When a simple disc, without outlines, is sufficient, it is more convenient to use Point
with AbsolutePointSize
:
VertexShapeFunction -> ({AbsolutePointSize[15], Point[#1]} &)
This avoids the vertices being cropped.