# How do I plot a function along a specified contour of parameters?

I have a scalar function (actually, a set of eigenvalues) which takes two parameters, say $$f(x,y)$$. I would like to make a 2D plot of this function for a continuous, closed loop of parameter values in the shape of a square, which would consist of four line segments connecting the four corners as $$(x(t),y(t)) = (0,0)\rightarrow(1,0)\rightarrow(1,1)\rightarrow(0,1)\rightarrow(0,0)$$ You can equivalently think of making a 3D plot of this function and tracing its value along a closed contour of parameters and plotting only this "cross section" of the function. I'm not sure how this can be implemented in Mathematica.

• Why not use Plot3D? Jun 18 at 23:44

Define a function you want to plot

f[x_, y_] := Cos[x] + Sin[y]


Interpolate over the path

p = Interpolation[{{0, {0, 0}}, {1, {0, 1}}, {2, {1, 1}}, {3, {1,
0}}, {4, {0, 0}}}, InterpolationOrder -> 1]


Plot

Plot[f @@ p[t], {t, 0, 4}] Improved plot

pts = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
dts = Norm /@ Differences[pts];
p = Interpolation[path, InterpolationOrder -> 1];
Plot[f @@ p[t], {t, 0, 4},
FrameTicks -> {{Automatic, None}, {path, None}},
GridLines -> {Accumulate[dts], None},
PlotTheme -> {"Monochrome", "Frame"}] • 3D
f[x_, y_] = 5 x*Sin[3 x*y] + Cos[8 x] + 2 + Sin[10 y];
Plot3D[f[x, y], {x, 0, 1}, {y, 0, 1}, BoundaryStyle -> {Thick, Red},
PlotStyle -> None, Mesh -> None, ViewProjection -> "Orthographic"] • 2D
f[x_, y_] = 5 x*Sin[3 x*y] + Cos[8 x] + 2 + Sin[10 y];
pts = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
lines = Partition[pts, 2, 1, 1];
plots = Table[
Plot[f @@ ((1 - t)*line[] + t*line[]), {t, 0, 1}], {line,
lines}];
GraphicsGrid[Partition[plots, 2, 2]] 