2
$\begingroup$

I am asking explicitly about the IGraphM package. I do the following:

<< IGraphM`
Clear[vrts, edgs, gr]
connections = {{1, 2}, {2, 3}, {2, 4}, {4, 5}, {5, 6}, {3, 6}};
vrts[1] = <|1 -> 1|>;
vrts[2] = <|2 -> 2|>;
edgs[1] = <|1 <-> 2 -> 1|>;
edgs[2] = <|3 <-> 6 -> 1|>;
g = Graph[UndirectedEdge @@@ connections];
gr[1] = {g, "VertexColors" -> vrts[1], "EdgeColors" -> edgs[1]};
gr[2] = {g, "VertexColors" -> vrts[2], "EdgeColors" -> edgs[1]};
gr[3] = {g, "VertexColors" -> vrts[1], "EdgeColors" -> edgs[2]};
IGVF2IsomorphicQ[gr[1], gr[1]]
IGVF2IsomorphicQ[gr[1], gr[2]]
IGVF2IsomorphicQ[gr[1], gr[3]]

There results are, of course, as expected. But now I would like to plot three graphs in order to show that they are indeed not isomorphic because of different colors of vertices/edges. I am suspecting that there is maybe a function from the same package that does exactly that. But I could not find. What is the idiomatic way to accomplish this?

$\endgroup$
  • $\begingroup$ Perhaps just do something using HighlightGraph? $\endgroup$ – jjc385 Dec 12 '17 at 4:29
  • $\begingroup$ @jjc385 Yes, that is one possibility. However, can it handle more that two colors? I actually know how to color a graph, but was hoping that there is already a function that can take advantage of "VertexColors" and "EdgeColors". $\endgroup$ – yarchik Dec 12 '17 at 7:29
  • 1
    $\begingroup$ I'll look into making this task easier for the next version. $\endgroup$ – Szabolcs Dec 13 '17 at 9:31
  • $\begingroup$ What version of Mathematica are you currently using? $\endgroup$ – Szabolcs Dec 16 '17 at 12:08
3
$\begingroup$

Well, the question was simple, so is the answer

decorateGraph[gr_, vrts_, edgs_] := Module[{gv},
  gv = Fold[
    SetProperty[{#1, #2}, {VertexStyle -> 
        ColorData[60, vrts[[Key[#2]]] ], VertexSize -> Medium}] &, g, 
    Keys[vrts]];
  Fold[SetProperty[{#1, #2}, 
     EdgeStyle -> {ColorData[60, edgs[[Key[#2]]]], Thick}] &, gv, 
   Keys[edgs]]
  ]

and apply

decorateGraph[g, vrts[2], edgs[2]]

enter image description here

$\endgroup$
0
$\begingroup$

I think your approach is just fine. I just wanted to show a slightly different implementation which I find easier to work with.

decorateGraph[g_?GraphQ, vc_?AssociationQ, ec_?AssociationQ] :=
 Graph[g,
  VertexStyle -> Normal[ColorData[60] /@ vc],
  EdgeStyle ->   Normal[{Thick, ColorData[60][#]} & /@ ec],
  VertexSize ->  Thread[Keys[vc] -> Medium],

  GraphStyle -> "BasicBlack" (* this is just to make the rest of the graph render in black *)
 ]

The key thing to notice is that when colours are given in the association form, they are just a few steps away from the form required in Graph-options: rule lists.

decorateGraph[g, vrts[2], edgs[2]]

enter image description here


Something to keep in mind is that Mathematica 11.2 changed the interpretation of <-> from UndirectedEdge to TwoWayRule. TwoWayRule should work everywhere where UndirectedEdge does, but due to some bugs it doesn't. Thus to make this work with your example, change <-> to UndirectedEdge (type it as ESC ue ESC)

IGraph/M will handle TwoWayRule in edge colour specifications starting with the next version (to be released before the end of 2017).


The next version of IGraph/M will make it easy to take vertex or edge colours from any existing graph attributes. If you do that, then IGVertexMap and IGEdgeMap will make it easy to visualize the graph. Unfortunately, working with graph attributes is still so cumbersome that it is not really worth the trouble in my opinion.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.