2
$\begingroup$
p1 = RegionPlot[   -(3/4) <= Sin[x y] <= 1/2 , {x, 0, 3}, {y, 0, 4},   
FrameLabel -> Automatic, PlotStyle -> LightBlue];

p2=Manipulate[  Show[p1, ContourPlot[Sin[x y] + z == 1  , {x, 0, 3}, {y, 0, 4}, 
FrameLabel -> Automatic, ContourStyle -> Black]], {z, 0, 1}]

and I get

enter image description here

Question:

Is it possible to exclude those $(x,y)$ which satisfy a general condition, say, $f(x,y)=const.$ from $p2$? In general, how we can exclude a condition (again, say, $f(x,y)=const.$) from the ContourPlot? for example, in the following simple code

ContourPlot[ Sin[x y]== 1/2 , {x, 0, 3}, {y, 0, 4}]
$\endgroup$
2
  • 1
    $\begingroup$ What is the f[x,y]? $\endgroup$
    – cvgmt
    Jan 31, 2022 at 2:33
  • $\begingroup$ @cvgmt It can be any two-variable function, say $\sin xy=\frac34$ ; I just want to know how to exclude a condition for the ContourPlot. $\endgroup$
    – math2021
    Jan 31, 2022 at 2:42

2 Answers 2

4
$\begingroup$

Excluded parts of a ContourPlot are White so set the style of the contour to be excluded to White

p1 = RegionPlot[-(3/4) <= Sin[x y] <= 1/2,
   {x, 0, 3}, {y, 0, 4},
   FrameLabel -> Automatic,
   PlotStyle -> LightBlue];

p2 = Manipulate[
  Show[p1,
   ContourPlot[
    {Sin[x y] + z == 1, Sin[x y] == 1/2},
    {x, 0, 3}, {y, 0, 4},
    ContourStyle -> {Black,
      Switch[state,
       exclude, White,
       normal, Lighter[Blue, 0.5],
       highlight, Red]}]],
  {{state, normal, "specified contour"}, {normal, highlight, exclude},
   ControlType -> RadioButton},
  {{z, 0.2}, 0, 1, 0.01, Appearance -> "Labeled"}]

enter image description here

$\endgroup$
4
$\begingroup$

Exclusions work for some functions.

Here we exclude y-2x==0

ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 4}, 
 Exclusions -> {y - 2 x == 0}, ContourStyle -> None, 
 Contours -> {-3/4, 1/2}, ContourShading -> {None, Blue, None}]
ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 4}, 
 RegionFunction -> Function[{x, y}, -3/4 <= Sin[x*y] <= 1/2], 
 Exclusions -> {y - 2 x == 0}, 
 ColorFunction -> (Blend[{Blue, Blue}, #] &), ContourStyle -> None]
DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 4}, 
 RegionFunction -> Function[{x, y}, -3/4 <= Sin[x*y] <= 1/2], 
 Exclusions -> {y - 2 x == 0}, 
 ColorFunction -> (Blend[{Blue, Blue}, #] &)]

enter image description here

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 4}, 
 RegionFunction -> Function[{x, y}, -3/4 <= Sin[x*y] <= 1/2], 
 Mesh -> None, PlotStyle -> Darker@Cyan, 
 Lighting -> {{"Ambient", White}}, ViewPoint -> Top, 
 ViewProjection -> "Orthographic", Exclusions -> {y - x == 0}, 
 Axes -> {True, True, False}]

enter image description here

$\endgroup$

Your Answer

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

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