3
$\begingroup$

In an array of plots of regions (inequalities) p[..] which are eventually combined using Show, how do I suppress the legend of plots which are empty, and look like this

enter image description here

More generally, if in a given range of $x$ and $y$ over which a region is prescribed to be plotted, if RegionPlot does not find a solution (so that there is no region to shade or fill), is there a way to get a True or False value from RegionPlot corresponding to whether the region exists or not?

$\endgroup$

2 Answers 2

3
$\begingroup$

You can express the region using ImplicitRegion and then plot it or check the area of the region. Example:

reg = ImplicitRegion[x^2 + y^3 < 2, {{x, -2, 2}, {y, -2, 2}}];
RegionPlot[reg]

Mathematica graphics

Chop@N@Area[reg]

9.91915

Checking to see if the area of the region is nonzero:

If[Chop@N@Area[reg] > 0, ...]
$\endgroup$
5
$\begingroup$
colors = RotateLeft[ColorData[97] /@ {1, 2, 3}];
regs = {x^2 < (y - 2)^3 + 1, (y + 2)^2 < (x - 2)^3 + 1, x + y <= -2}; 

Show[With[{col = First[colors = RotateRight[colors]]}, 
    RegionPlot[#, {x, -5, 5}, {y, -5, 5}, PlotStyle -> col, 
     PlotLegends -> If[Area[ImplicitRegion[#, {{x, -5, 5}, {y, -5, 5}}]] === 0, None, {#}], 
     PlotRange -> {{-5, 5}, {-5, 5}}]] & /@ (And[#, True] & /@ regs)]

enter image description here

Replace And[#, True] & with And[#, x >= 2 y] & to get

enter image description here

Replace And[#, True] & with And[#, x <= y] & to get

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.