3
$\begingroup$

I need to draw a contour figure defined by coordinate x and y. The domain is a rectangle (-100<=x<=100,-100<=y<=100) excluding a circle (center at the origin, and radius of 5). The object function is 'z=x+y'.

What confuses me is how to exclude the circle from the rectangle. How can I draw such a contour figure?

$\endgroup$
2
$\begingroup$

You can also use ConditionalExpression as the first argument of ContourPlot:

ContourPlot[ConditionalExpression[x + y, x^2 + y^2 >= 5^2],
  {x, -100, 100}, {y, -100, 100},  PlotLegends -> Automatic]

enter image description here

$\endgroup$
6
$\begingroup$

How about this?

ContourPlot[x + y, {x, -100, 100}, {y, -100, 100}, 
 RegionFunction -> Function[{x, y, z}, x^2 + y^2 >= 5^2], 
 PlotPoints -> 100, PerformanceGoal -> "Quality", 
 PlotLegends -> Automatic, ColorFunction -> "ThermometerColors"]

enter image description here

If the smoothness of disk bothers you (it bothers me), you can cheat it like so:

Show[ContourPlot[x + y, {x, -100, 100}, {y, -100, 100}, 
  PlotPoints -> 100, PerformanceGoal -> "Quality", 
  PlotLegends -> Automatic, ColorFunction -> "ThermometerColors"], 
 Graphics[{White, Disk[{0, 0}, 5]}]]

enter image description here

$\endgroup$
  • $\begingroup$ Nice quality of the figure! Got it~ Thank you! $\endgroup$ – Robin_Lyn Nov 15 '18 at 6:07

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.