I have a graph that I generated using upper half-plane. The graph will become bigger as I increase the iteration. For example, at first iteration, this is the graph that is generated. First iteration

And this is the graph generated at tenth iteration. 10th iteration

So, my question is how can I denote all the vertex in the graph in integer form? I have try using Show[SetProperty[G, VertexLabels -> "Name"], PlotRange -> All] . vertexlabels

I have also used the replace method by replacing the vertex coordinates to an integer. But I can only do that if the graph size is small. What can I do if the graph size is large?


1 Answer 1


Use IndexGraph.


g = NearestNeighborGraph[RandomReal[1, {10, 2}], VertexLabels -> "Name"]

enter image description here


enter image description here

If you only want to change how the vertices are labelled in the visualization, but you do not want to change the names that you use to refer to them in your program, then simply use the option

VertexLabels -> "Index"
  • $\begingroup$ It works! Thank you so much @Szabolcs. $\endgroup$ Commented Feb 19, 2018 at 14:45

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.