2
$\begingroup$

I want to combine three RegionPlot, and I need to do this in a way such that the overlapping and intersection parts of the plots are visible and clear. I use this code and use Opacity for their colors

p1 = RegionPlot[x - y < 0, {x, 0, 6}, {y, 0, 6},  PlotStyle -> Directive[Blue, Opacity[0.2]], BoundaryStyle -> None];
p2 = RegionPlot[2 y - x < 0 , {x, 0, 6}, {y, 0, 6},   PlotStyle -> Directive[Green, Opacity[0.2]], BoundaryStyle -> None];
p3 := RegionPlot[y Sin[x] < 0 , {x, 0, 6}, {y, 0, 6},    PlotStyle -> Directive[Red, Opacity[0.2]], BoundaryStyle -> None];

Show[{p1, p2, p3}]

when I save the result as PDF, there are these grid line polygons (as the picture attached). According to the other similar problems in SE, this is a bug.

Question Is there an alternative way to obtain this overlapping result without using Opacity? So that the result it gives is a clear plain color?

enter image description here

$\endgroup$

1 Answer 1

5
$\begingroup$
Clear["Global`*"]

cond = {x - y < 0, 2 y - x < 0, y Sin[x] < 0};

colors = {LightBlue, LightGreen, LightRed};

gr2 = RegionPlot[Evaluate[Join[cond, And @@@ Subsets[cond, {2}]]],
  {x, 0, 6}, {y, 0, 6},
  PlotStyle -> Join[colors, Blend[#, 1/2] & /@ Subsets[colors, {2}]],
  BoundaryStyle -> None]

enter image description here

Export["/Users/roberthanlon/Downloads/gr2.pdf", gr2];

Import["/Users/roberthanlon/Downloads/gr2.pdf"][[1]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you for the great answer. But if the three conditions are not that simple; say each $p_1$, $p_2$, and $p_3$ need to be used with very high precision separately, accordingly, the only way is to use Show to combine them; in that case, is there any alternatives? @Bob Hanlon $\endgroup$
    – Martha97
    Commented Feb 26, 2022 at 20:17
  • 1
    $\begingroup$ I don't think it is a precision issue. If there are overlaps between more than two regions in an area, the determination of the appropriate colors becomes more involved. I don't know of any method using Show that doesn't have the problem you are trying to avoid. $\endgroup$
    – Bob Hanlon
    Commented Feb 26, 2022 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.