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.
Asked
Active
Viewed 185 times
1
-
Using `Graph`, it is not possible. After converting to `Graphics` (with `Show`), you can draw a `Polygon` using the vertex coordinates of those three vertices. – Szabolcs Dec 06 '12 at 16:10
-
I want to create square, divide it into n^2 small squares and color random(or I assign a number to each boxes and color prime numbered ones) boxes with red. I want to use graph because I want to color vertices with colours too. The vertices of graph. – Dec 06 '12 at 16:25
-
Or is there any other function that allows to render edges as well as fill colours. – Dec 06 '12 at 16:32
1 Answers
1
A one very easy way would be to use image processing:
g = RandomGraph[{10, 15}, ImageSize -> 600, EdgeStyle -> Thick]
MorphologicalComponents[Binarize@Image[g]] // Colorize
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

Vitaliy Kaurov
- 1,298
- 7
- 21
-
It also gives me a new perspective. Can I count the number of parts coloured in pink in graph above? You added something. I meant the graph above the squares. – Dec 06 '12 at 17:01
-
@user1709828 Coloring is random and I think unique, I think those are not two the same "pinks". But generally read documentation on MorphologicalComponents - a lot of related useful stuff there. – Vitaliy Kaurov Dec 06 '12 at 17:04
-
One more thing. Can I COUNT number of objects in graphics. I mean number of disconnected ones. I want to remove everything other than a certain colour if it exists and count it. Is that possible. – Dec 06 '12 at 17:16
-
@user1709828 `MorphologicalComponents` gives numerical information - number of regions, etc. – that can be counted. Also take a look at `RegionBinarize` which allows coloring selectively based on a position of any point inside a region. – Vitaliy Kaurov Dec 06 '12 at 17:21