Message Boards Message Boards

1
|
8719 Views
|
5 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Extracting the VertexStyle replacement rule list

I have the following graph.
In[622]:= InputForm[g1]
Out[622]//InputForm=
Graph[{1, 2, 3, 4, 5, 6}, {UndirectedEdge[1, 2],
 UndirectedEdge[2, 3], UndirectedEdge[3, 4],
 UndirectedEdge[4, 5], UndirectedEdge[5, 6],
 UndirectedEdge[6, 1]},  {VertexStyle -> {2 -> RGBColor[0, 1, 0], 1 -> RGBColor[0, 0, 1],
  5 -> RGBColor[0, 1, 0], 6 -> RGBColor[1, 0, 0],
  4 -> RGBColor[0, 0, 1], 3 -> RGBColor[1, 0, 0]}}]

Is there a clean way to extract the VertexStyle replacement rule list? I found documentation for how to set properties, and I have seeen how one might extract on a per-vertex (or per-edge) basis with PropertyValue. But I've not found how to extract them as a whole.

Danny
POSTED BY: Daniel Lichtblau
5 Replies
If you need separate style, a somewhat more reliable way would be this
# -> PropertyValue[{g,#}, VertexStyle]& /@ VertexList[g]

This'll also work in cases like g = CompleteGraph[5, VertexStyle -> Red].  Unfortunately I find the property system for graphs somewhat cumbersome and unpredictable to work with... 
POSTED BY: Szabolcs Horvát
Maybe this feels more familiar:
In[57]:= Options[gg, VertexStyle] 
Out[57]= {VertexStyle -> {3 -> RGBColor[1, 0, 0], 6 -> RGBColor[1, 0, 0],
                          5 -> RGBColor[0, 1, 0], 2 -> RGBColor[0, 1, 0],
                          4 -> RGBColor[0, 0, 1], 1 -> RGBColor[0, 0, 1]}}
POSTED BY: Charles Pooh
Craig, Paritosh, thanks, - close enough. What I want (below) is trivial to construct with yours.
VertexStyle -> {2 -> RGBColor[0, 1, 0], 1 -> RGBColor[0, 0, 1],
   5 -> RGBColor[0, 1, 0], 6 -> RGBColor[1, 0, 0],
   4 -> RGBColor[0, 0, 1], 3 -> RGBColor[1, 0, 0]}
POSTED BY: Daniel Lichtblau
Is this what you are looking for?
 In[526]:=
 gg = Graph[{1, 2, 3, 4, 5, 6}, {UndirectedEdge[1, 2],
   UndirectedEdge[2, 3], UndirectedEdge[3, 4], UndirectedEdge[4, 5],
   UndirectedEdge[5, 6],
   UndirectedEdge[6,
    1]}, {VertexStyle -> {2 -> RGBColor[0, 1, 0],
    1 -> RGBColor[0, 0, 1], 5 -> RGBColor[0, 1, 0],
    6 -> RGBColor[1, 0, 0], 4 -> RGBColor[0, 0, 1],
    3 -> RGBColor[1, 0, 0]}}]; 
In[527]:= PropertyValue[gg, VertexStyle]
Out[527]= {3 -> RGBColor[1, 0, 0], 6 -> RGBColor[1, 0, 0],
5 -> RGBColor[0, 1, 0], 2 -> RGBColor[0, 1, 0],
4 -> RGBColor[0, 0, 1], 1 -> RGBColor[0, 0, 1]}
POSTED BY: Paritosh Mokhasi
Hello Dan,
Are you looking for this?
PropertyValue[g1, VertexStyle]
From your post, tt seems like you've already tried this---but isn't it giving you all the vertices?

Craig
POSTED BY: W. Craig Carter
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract