# How to use plot parametric function with discrete data?

You can easily create a ParametricPlot using the syntax ParametricPlot[{fx, fy}, {t, tmin, tmax}] when you have the functions fx and fy explicitly. However, what if you only have a discrete version of {fx, fy}? Can you still create a ParametricPlot?

I am considering trying this method using discrete data exported from another software. Here is a minimal working example:

fx = Table[{t, Sin[t]}, {t, 0, 2 Pi, 0.1}];
fy = Table[{t, Sin[2 t]}, {t, 0, 2 Pi, 0.1}];
ParametricPlot[{fx, fy}, {t, 0, 2 Pi}]


I expect the output of the plot to closely resemble that of the continuous version.

ParametricPlot[{Sin[t], Sin[2 t]}, {t, 0, 2 Pi}]

• Maybe ListPlot[Transpose[{fx[[;; , 2]], fy[[;; , 2]]}], Joined -> True]. Jun 17, 2023 at 9:06
• @cvgmt thanks, it works. I sampled more points so it looks very similar to the continous version. Jun 17, 2023 at 9:08

We can eliminate the first common variable then get the co-relationship.

ListPlot[Transpose[{fx[[;; , 2]], fy[[;; , 2]]}], Joined -> True]


xy = Transpose[{fx[[All, 2]], fy[[All, 2]]}];

BSF = BSplineFunction[xy, SplineDegree -> 1];

ParametricPlot[BSF @ t, {t, 0, 1},
Epilog -> {PointSize[Large], ColorData[97] @ 1, Point @ BSF["ControlPoints"]}]


Alternatively,

ParametricPlot[{fx[[IntegerPart @ t, 2]], fy[[IntegerPart @ t, 2]]},
{t, 1, Length @ fx}, Mesh -> All, MeshStyle -> PointSize[Large]]


• I just updated the expected output, could you update the answer as well? Jun 17, 2023 at 9:10
• @internet, updated.
– kglr
Jun 17, 2023 at 9:21
• BSplineFunction[] doesn't pass over the points except with the option SplineDegree->1. It's not visible in the graphics above. One can see this by reducing the number of points Jun 17, 2023 at 13:13
• Thank you @andre314; very good point. I updated with the option.
– kglr
Jun 17, 2023 at 14:31
• @internet, ColorData[97] @ # should be ColorData[97] @ 1 (i updated with the correction). Re crowded mesh points, it is probably version-related -- I am using 13.1.0 for Linux x86 (64-bit)
– kglr
Jun 17, 2023 at 15:34
\$Version

(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)

Clear["Global*"]

fx = Table[{t, Sin[t]}, {t, 0, 2 Pi, 0.1}];
fy = Table[{t, Sin[2 t]}, {t, 0, 2 Pi, 0.1}];

ParametricPlot[{Interpolation[fx][t], Interpolation[fy][t]}, {t, 0, 2 Pi},
AxesLabel -> (Style[#, 14] & /@ {HoldForm[x], HoldForm[y]}),
ColorFunction -> Function[{x, y, t}, ColorData["Rainbow"][t]],
PlotLegends -> BarLegend[{"Rainbow", {0, 2 Pi}},
LegendLabel -> Style[HoldForm[t], 14]]]
`