# Contour Plot: Selecting the contour line that crosses a specific point

I have a very complicated function $$f(u,v)$$ in the complex $$u,v$$ plane which has several contours with the same value $$x$$, so that when I draw a ContourPlot of the equation $$f(u,v)=x$$ I get several lines (far too many, it crowds the graphic).

However, I am actually only interested in those contours that cross a given point $$(u_0,v_0)$$ of my function. Consider the following minimal working example:

ContourPlot[u Cos[v] == 1, {u, -3, 3}, {v, -3, 3}, Epilog -> {Red, PointSize[Medium], Point[{1, 0}]}]


I would like to single out the contour which crosses the point $$(1,0)$$ (indicated by the red dot) and throw the other contours away:

How do I implement the condition that the contour must cross a given point?

NB: For the MWE above, it is simple to exclude the unwanted contours by specifying $$x<0$$. I am not interested in that. I have a very messy function and the only criteria that separates the contour of interest from the others is that it crosses a point of interest.

EDIT:

So I have come up with an example that reproduces my issue with klgr's very good solution: all contours disappear, even the one of interest.

If I come up with a slightly more complicated function where the contours touch then this method cannot choose the line which crosses the point of interest:

ContourPlot[1/x Cos[y] == 1, {x, -3, 3}, {y, -3, 3},MaxRecursion -> 6, Epilog -> {Red, PointSize[Medium], Point[{1, 0}]}]


If I use klgr's method however,

Normal[ContourPlot[1/x Cos[y] == 1, {x, -3, 3}, {y, -3, 3}, MaxRecursion -> 6, Epilog -> {Red, PointSize[Medium], Point[{1, 0}]}]] /. l_Line :> If[RegionMember[l, {1, 0}], l, Nothing]


then all contours vanish!

One way is to post-process to remove the contour lines that do not pass through {1,0}:

Normal[ContourPlot[u Cos[v] == 1, {u, -3, 3}, {v, -3, 3},
Epilog -> {Red, PointSize[Medium], Point[{1, 0}]}] ] /.
l_Line :> If[RegionMember[l, {1, 0}], l, Nothing]


Update: You can add the option PlotPoints -> 100 to get something that works for both examples in OP:

cp1 = ContourPlot[1/x Cos[y] == 1, {x, -3, 3}, {y, -3, 3},
PlotPoints -> 100,
Epilog -> {Red, PointSize[Medium], Point[{1, 0}]},
ImageSize -> Small];
Row[{cp1,
Normal[cp1] /. l_Line :> If[RegionMember[l, {1, 0}], l, Nothing]}]


If we color the three pieces of the contour individually:

i = 1; cp2 =
ContourPlot[1/x Cos[y] == 1, {x, -3, 3}, {y, -3, 3},
PlotPoints -> 100,
Epilog -> {Red, PointSize[Medium], Point[{1, 0}]},
ImageSize -> Small] /. l_Line :> {ColorData[97][i++], l};
Row[{cp2,
Normal[cp2] /. l_Line :> If[RegionMember[l, {1, 0}], l, Nothing]}]


With Exlusions -> None one of the pieces is a closed curve:

i = 1;
cp3 = ContourPlot[1/x Cos[y] == 1, {x, -3, 3}, {y, -3, 3},
Exclusions -> None, PlotPoints -> 100,
Epilog -> {Red, PointSize[Medium], Point[{1, 0}]},
ImageSize -> Small] /. l_Line :> {ColorData[97][i++], l};
Row[{cp3,
Normal[cp3] /. l_Line :> If[RegionMember[l, {1, 0}], l, Nothing]}]


\$Version


"11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"

• So this solution seems to work for the MWE. However, in my code the method rules out all contour lines. I'm thinking the issue might be to do with Accuracy or Precision between ContourPlot and how I specify my point but I haven't found a work around. Any suggestions? Jan 30, 2019 at 10:26
• @OldTomMorris, maybe something like l_Line :> If[RegionDisjoint[l, Disk[{1, 0}, .001]], Nothing, l] in ReplaceAll?
– kglr
Jan 30, 2019 at 10:40
• The only issue being I am running Mathematica 10.3 and not 11.1! Jan 30, 2019 at 10:50
• @OldTomMorris, have you tried increasing PlotPoints and MaxRecursion?
– kglr
Jan 30, 2019 at 10:55
• Yes. PlotPoints -> 50 and MaxRecursion -> 4 give me nothing too. I also tried a variant of the RegionDisjoint using Element but that didn't sem to work either. Jan 30, 2019 at 11:18