Question

Is there a way to colour region bounded by edges with GRAPH in mathematica. Like if three vertices form a triangle, I want to colour the are of triangle with GRAPH option.

Was it helpful?

Solution

A one very easy way would be to use image processing:

g = RandomGraph[{10, 15}, ImageSize -> 600, EdgeStyle -> Thick]

enter image description here

MorphologicalComponents[Binarize@Image[g]] // Colorize

enter image description here

It is easy for planar graphs, but for the rest you may have some overlapping regions. I see you mentioned grid; this is how you can approach it:

g = GridGraph[{5, 5}, VertexSize -> .5, EdgeStyle -> Thick];
MorphologicalComponents[ColorNegate@Binarize@GradientFilter[Image[g], 1]] // Colorize

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top