0
$\begingroup$

I put a couple of previous posts together

How can find the 2D Voronoi cell area distribution?

Color code Voronoi cell areas depending on number of vertices

color voronoi cell based on area

to make the below script, but honestly I do not know what is going on so I cannot change it properly. my questions:

  • Colouring the cells by their area; how can I improve the figure visually (increasing the contrast between the colors)? as you can see due to the larger cells the BarLegend and the colouring does not help that much to differentiate the cells which their areas are close. Is it possible to dismiss the cells which have larger area (say if area > sth ) and leave them as uncoloured (white) cells?

  • Another post shows how to colour the cells based on the number of vertices. How can I add BarLegend to this plot to highlight which colour corresponds to which number of vertices?

  • Is it possible to use Voronoi diagram for a number of points? I mean having for example 7 points in each cell rather than 1 point and apply the method. Probably one way is to replace the i.e. 7 points with their geometrical mean point manually and apply the Voronoi diagram, but I think for large number of data points it is not a good idea.

Thank you all for sharing your knowledge and expertise.

Here is my script:

    d1 = ReadList["f1", {Number, Number}];

mesh0 = VoronoiMesh[d1, {-275, 275}, Axes -> True, PlotTheme -> "Lines"]

mesh = Graphics[{FaceForm[None], EdgeForm[Black], 
   MeshPrimitives[mesh0, {2, "Interior"}]}]

areas = PropertyValue[{mesh0, 2}, MeshCellMeasure];
MinMax[areas]
Legended[SetProperty[{mesh0, {2, All}}, 
  MeshCellStyle -> ColorData["Rainbow"] /@ Rescale[areas]], 
 BarLegend[{"Rainbow", MinMax[areas]}]]

colorvm = 
  Map[{ColorData[97, First[Dimensions[First[#]]] - 2], #} &, 
   MeshPrimitives[mesh0, {2, "Interior"}]];
Legended[Graphics[{EdgeForm[Black], colorvm}, 
  PlotRange -> {{-275, 275}, {-275, 275}}], 
 BarLegend["Rainbow", {3, 7}]]

You can find the data here enter link description here

Edit: After @J.M.'sennui's comment, here you can find the new images; colour by area and colour by vertices

enter image description here enter image description here

$\endgroup$
5
  • 2
    $\begingroup$ "How can I trim/crop the Voronoi mesh?" - did you look at the docs for VoronoiMesh[], and the second argument in particular? "I cannot find the link to upload my data" - go to pastebin.com, post your data there, and link to it here. $\endgroup$ – J. M.'s torpor Jan 22 at 9:13
  • $\begingroup$ @J.M. Thank you so much; I just noticed the xmin, xmax. $\endgroup$ – Aa Aa Jan 22 at 9:19
  • $\begingroup$ @J.M., Thank you very much, it solved a large portion of the problems, but still needs some adjustment for colouring and the BarLegend. $\endgroup$ – Aa Aa Jan 22 at 9:27
  • 2
    $\begingroup$ AA, Please edit your question to blend your changes after JM's comment and remove any parts that are no longer relevant. If any questions remain, please highlight them. You don't want us to have to puzzle through your question to figure out what you still need help with. $\endgroup$ – MarcoB Jan 22 at 15:04
  • $\begingroup$ @MarcoB, Thank you, I have corrected my post. $\endgroup$ – Aa Aa Jan 22 at 16:30

Your Answer

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

Browse other questions tagged or ask your own question.