# color voronoi cell based on area

According to mrz's question: Color code Voronoi cell areas depending on number of vertices, he colored voronoi cell by number of corners corresponding to a Voronoi cell.

My question is how to colorize voronoi cell by area of every cell, for example we have a mesh as follows:

pts = RandomReal[{-1, 1}, {25, 2}];
VoronoiMesh[pts]


I want to colorize the cells with different gradient in gray,i.e., 0.1mm^2(light gray)~1mm^2(dark gray). Or add a color function to differentiate every cell based on their own area, in other words, the cells have same value in area share same color.

Thank you!

pts = RandomReal[{-1, 1}, {25, 2}];
v = VoronoiMesh[pts];
mp = MeshPrimitives[v, 2];
a = Rescale[Area /@ mp];
Legended[Graphics[
BarLegend["Rainbow"]]


The barlegend is scale 0 to 1 relative to maximum area. Obviously this can be modified to achieve desired result.

• Thank you ubpdqn! Your answer works well in my case. Regards,Shuoqi Commented Apr 4, 2017 at 4:33

You can also work with mesh properties, like so:

pts = RandomReal[{-1, 1}, {25, 2}];
mesh = VoronoiMesh[pts];

areas = PropertyValue[{mesh, 2}, MeshCellMeasure];

Legended[
SetProperty[{mesh, {2, All}}, MeshCellStyle -> ColorData["Rainbow"] /@ Rescale[areas]],
BarLegend[{"Rainbow", MinMax[areas]}]
]