# Plot the lines (nodes) for the given value from NDsolve output

I want to plot lines for a specific single value from the output in Nsolve (we need to find these nodes from the output ufun, then plot them).

 ufun = NDSolveValue[{-Laplacian[u[x, y], {x, y}] == 10, u[x, 0] == 0,
u[x, 1] == 1}, u, {x, 0, 1}, {y, 0, 1}];
ContourPlot[ufun[x, y], {x, 0, 1}, {y, 0, 1},
ColorFunction -> "TemperatureMap",
PlotRange -> MinMax[ufun["ValuesOnGrid"]],
PlotLegends -> BarLegend[Automatic], AspectRatio -> Automatic]


The results something like, the given value is 1.5, the lines are denoted by red

I don't know what is meant by "nodes" but this gives the indicated graphics:

ufun = NDSolveValue[{-Laplacian[u[x, y], {x, y}] == 10, u[x, 0] == 0,
u[x, 1] == 1}, u, {x, 0, 1}, {y, 0, 1}];
cp = ContourPlot[ufun[x, y], {x, 0, 1}, {y, 0, 1},
ColorFunction -> "TemperatureMap",
PlotRange -> MinMax[ufun["ValuesOnGrid"]],
PlotLegends -> BarLegend[Automatic], AspectRatio -> Automatic];
lines = ContourPlot[ufun[x, y] == 1.5, {x, 0, 1}, {y, 0, 1},
ContourStyle -> Red];
Show[cp, lines]


This gives the points computed by ContourPlot for each line:

Cases[Normal@lines, Line[p_] :> p, Infinity]
(* two lines/tables of points/nodes
{
{{0., 0.35518590998042887}, {0.0020263424518760335,
0.35511651469098104}, ..., {1., 0.35518590998043176}},
{{0., 0.8443496801705759}, {0.012332990750256536,
0.8448098663926003}, ..., {1., 0.8443496801705764}}
}
*)

• thanks, it is solved now! Commented Aug 27, 2021 at 12:12
• @ABCDEMMM You're welcome. Commented Aug 27, 2021 at 12:12
• can we get these selected points (nodes) as a table/list in MMA ? Commented Aug 27, 2021 at 12:17
• @ABCDEMMM You want the coordinates of the points on each red line? That can be done. Note they are not points computed by NDSolve. They are computed by ContourPlot from the interpolation. Commented Aug 27, 2021 at 12:30

You can use the options MeshFunctions, Mesh and MeshStyle as follows:

ContourPlot[ufun[x, y], {x, 0, 1}, {y, 0, 1},
ColorFunction -> "TemperatureMap",
PlotRange -> MinMax[ufun["ValuesOnGrid"]],
PlotLegends -> BarLegend[Automatic],
MeshFunctions -> {#3 &},
Mesh -> {{1.5}},
MeshStyle -> Directive[Thick, CapForm["Butt"], Red],
AspectRatio -> Automatic]


Do I understand that right that you want to include the red lines in the plot? In that case have a look at the code below:

ufun = NDSolveValue[{-Laplacian[u[x, y], {x, y}] == 10, u[x, 0] == 0,
u[x, 1] == 1}, u, {x, 0, 1}, {y, 0, 1}];
ContourPlot[ufun[x, y], {x, 0, 1}, {y, 0, 1},
ColorFunction -> "TemperatureMap",
PlotRange -> MinMax[ufun["ValuesOnGrid"]],
PlotLegends -> BarLegend[Automatic], AspectRatio -> Automatic,
Epilog -> {Red, Line[{{0, 0.85}, {1, 0.85}}],
Line[{{0, 0.35}, {1, 0.35}}]}]