5
$\begingroup$

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}]
$\endgroup$
2
  • 2
    $\begingroup$ Maybe ListPlot[Transpose[{fx[[;; , 2]], fy[[;; , 2]]}], Joined -> True]. $\endgroup$
    – cvgmt
    Jun 17, 2023 at 9:06
  • $\begingroup$ @cvgmt thanks, it works. I sampled more points so it looks very similar to the continous version. $\endgroup$
    – internet
    Jun 17, 2023 at 9:08

3 Answers 3

5
$\begingroup$

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

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

enter image description here

$\endgroup$
4
$\begingroup$
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"]}]

enter image description here

Alternatively,

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

enter image description here

$\endgroup$
6
  • $\begingroup$ I just updated the expected output, could you update the answer as well? $\endgroup$
    – internet
    Jun 17, 2023 at 9:10
  • $\begingroup$ @internet, updated. $\endgroup$
    – kglr
    Jun 17, 2023 at 9:21
  • 1
    $\begingroup$ 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 $\endgroup$
    – andre314
    Jun 17, 2023 at 13:13
  • $\begingroup$ Thank you @andre314; very good point. I updated with the option. $\endgroup$
    – kglr
    Jun 17, 2023 at 14:31
  • 1
    $\begingroup$ @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) $\endgroup$
    – kglr
    Jun 17, 2023 at 15:34
2
$\begingroup$
$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}];

Use Interpolation

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]]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.