4
$\begingroup$

The plane is divided into a grid and points is distributed on it.

num = 100;
r = N[1/20];
points = RandomReal[{0, 1}, {num, 2}];
fig = ListPlot[points, GridLines -> {Range[0, 1, r], Range[0, 1, r]}, 
  PlotMarkers -> {Automatic, 3.5}, PlotStyle -> Red, 
  ImageSize -> 1000]

I am interested in colorizing specific regions in the plane.

fig2 = Graphics[{Green, Rectangle[]}, 
  PlotRange -> {{0.7`, 0.4`}, {0.75`, 0.45`}}]
Show[fig2, fig]

But someting go wrong, any sugestion on how to do it correct? Aditionlly how to extend it to few squares in plane?

$\endgroup$
  • $\begingroup$ The problem is that options in the first item in Show override options given in the later ones. In this case, the settings for axes and gridlines are taken from fig2, i.e. are not included at all. The plot range of fig2 becomes the plot range for the combined figure. $\endgroup$ – C. E. Sep 7 at 19:33
5
$\begingroup$
num = 100;
r = N[1/20];
points = RandomReal[{0, 1}, {num, 2}];
coord = {{0.7`, 0.4`}, {0.75`, 0.45`}};
fig = ListPlot[points,
  GridLines -> {Range[0, 1, r], Range[0, 1, r]},
  PlotMarkers -> {Automatic, 3.5},
  PlotStyle -> Red,
  ImageSize -> 1000
  , Epilog -> {{Green, Opacity[.5], Rectangle @@ coord}}
  ]

enter image description here

$\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.