2
$\begingroup$

How do I show intersecting points on a contour graph? I have 2 functions graphed but I cannot figure out how to show the points of their intersections.

$\endgroup$
  • 2
    $\begingroup$ Please be more specific: you have the expression of f and g? If you want the intersection of the 2 graphs, try to plot f - g = 0. $\endgroup$ – youyou May 12 at 18:05
3
$\begingroup$
f[x_, y_] := Abs[Sin[x] Sin[y]] - .5
g[x_, y_] := Abs[Cos[x] Cos[y]] - .25

Three alternative methods:

1. Use Solve to find the intersections and add the intersection points as Epilog in ContourPlot:

intersections = {x, y} /. 
   Solve[{f[x, y] == 0, g[x, y] == 0, -3 <= x <= 3 && -3 <= y <= 3}, {x, y}];

ContourPlot[{f[x, y] == 0, g[x, y] == 0}, {x, -3, 3}, {y, -3, 3}, 
 PlotLegends -> "Expressions", 
 Epilog -> {Red, PointSize[Large], Point@intersections}]

enter image description here

2. Use Graphics`Mesh`FindIntersections to find the intersections of contour lines and add the corresponding points using a combination of options Epilog and DisplayFunction:

ContourPlot[{f[x, y] == 0, g[x, y] == 0}, {x, -3, 3}, {y, -3, 3}, 
 PlotLegends -> "Expressions", 
 DisplayFunction -> (Show[#, Epilog -> {Red, PointSize[Large], 
   Point@Graphics`Mesh`FindIntersections[#[[1]], Graphics`Mesh`AllPoints -> False]}] &)]

enter image description here

3. Use the options MeshFunctions and Mesh:

ContourPlot[{f[x, y] == 0, g[x, y] == 0}, {x, -3, 3}, {y, -3, 3}, 
 PlotLegends -> "Expressions", 
 MeshFunctions -> {g[#, #2] - f[#, #2] &}, 
 Mesh -> {{{0, Directive[Red, PointSize[Large]]}}}]

enter image description here

Note: The last two methods do not work if some contours are tangent to each other.

| improve this answer | |
$\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.