# How can we get a line plot along x or y from a 2D plot?

I have 2D data $$f(x,y)$$ and would like to get a plot along either of the axes, i.e. $$f(x_0,y)$$ or $$f(x,y_0)$$.

twoDdata = Table[{x, y, Cos[y ] Sin[x]}, {x, 0, 2 \[Pi], \[Pi]/20}, {y, 0,
2 \[Pi], \[Pi]/20}];
ListDensityPlot[Flatten[twoDdata, 1], ColorFunction -> "Rainbow", PlotLegends -> Automatic] what is the best way to get a line plot along the black and brown lines in the Fig above?

here is my idea for the brown one

ListLinePlot[twoDdata[][[All, {2, 3}]]] How can we do it similarly but along the black line? Are there more elegant ways to do that?

Or use the 3D version.

Clear[c];
twoDdata =
Table[{x, y, Cos[y] Sin[x]}, {x, 0, 2 π, π/20}, {y, 0,
2 π, π/20}];
c = 3.5;
ListPlot3D[Flatten[twoDdata, 1], ColorFunction -> "Rainbow",
PlotLegends -> Automatic, MeshFunctions -> {#2 &}, Mesh -> {{c}},
MeshStyle -> Thick, ViewPoint -> Front, PlotStyle -> None,
BoundaryStyle -> None, ViewProjection -> "Orthographic",
AxesEdge -> {Automatic, None, Automatic},
PerformanceGoal -> "Quality"] /. {(VertexColors -> None) ->
VertexColors -> Automatic} How can we do it similarly but along the black line?

I think this does it

twoDdata[[All, 20]][[All, {1, 3}]];
ListLinePlot[%] I picked the 20'th column by inspection as there are 41 columns and this is about half way. If you have specific value for the y coordinates this can be improved.

This is how rowDdata is structured: First row contains all entries related for first $$x$$ value. Second row contains all entries related to second $$x$$ value, and so on.

Each row of rowDdata in turn is matrix whose each row is for the corresponding $$x,y,f(x,y)$$ value for that fixed $$x$$ and changing $$y$$.

So to pick the samples for the 20's y-value, that will be twoDdata[[All, 20]]. This gives a matrix with 3 entries in each row and has as many entries are there are $$x$$ values. Then twoDdata[[All, 20]][[All, {1, 3}]] picks the $$x$$ and $$f(x,y)$$ values from that matrix.