TransWikia.com

Displaying Vertex indices in different colour than vertices

Mathematica Asked on May 7, 2021

graph1 = SetProperty[graph1, VertexLabels -> Table[i -> Placed[{Style[i, Blue], 
    Style[PropertyValue[{graph1, i}, VertexIndex], Red]}, {Before, After}], 
{i, VertexList[graph1]}]]

does not display the indices in Red (gives an error).

is there a way to fix this?

This question is related to: Graphs: colouring vertex weights differently from vertices

One Answer

Try

graph1 = SetProperty[graph1,VertexLabels->Table[i->Placed[
  {Style[i,Blue], 
   Style[VertexIndex[graph1,i],Red]}
,{Before,After}],{i,VertexList[graph1]}]]

It turns out PropertyValue is being replaced by AnnotationValue. Even so, calling AnnotationKeys[{graph1,First@VertexList[graph1]}] shows that a graph vertex has the following inbuilt annotations (formerly properties)

{VertexCoordinates,VertexShape,VertexShapeFunction,VertexSize,VertexStyle}

VertexIndex is a function on graphs just like VertexList, vertices do not store their index.

Correct answer by Adam on May 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP