4
$\begingroup$

From an examplary plot

plot = ParametricPlot[{1 Cos[s] , 2 Sin[s]}, {s, 0, 2 Pi}]

I know how to get the plotted points

pi = Cases[plot, Line[p_] :> p, Infinity][[1]];
 

Additionally I would like to get the parametervalues s (automatically used by ParametricPlot) of the plotted points pi: {s[i],p[i]}

How to do that? Thanks!

$\endgroup$
6
  • $\begingroup$ for the specific example, angles = First@Cases[pp, Line[x_] :> ArcTan @@@ x, All]. $\endgroup$
    – kglr
    Dec 5 '21 at 10:58
  • $\begingroup$ @kglr Thanks, the example seems to be to easy. How to proceed if you don't know the context between Point and Parameter? $\endgroup$ Dec 5 '21 at 11:03
  • $\begingroup$ would this be cheating: f[s_] = {1 Cos[s], 2 Sin[s]}; {plot, evals} = Reap[Block[{e = 0}, ParametricPlot[f[s], {s, 0, 2 Pi}, EvaluationMonitor :> Sow[Tooltip[{Opacity[0], Point[f@s]}, s]]]]]; Show[plot, Graphics[{Red, evals}]]? $\endgroup$
    – kglr
    Dec 5 '21 at 11:04
  • $\begingroup$ @kglr ParametricPlot uses a set of parametervalues s[ i] for every plotted point p[i]. Unfortunately plot doesn't keep this context. $\endgroup$ Dec 5 '21 at 11:10
  • $\begingroup$ .. that is, we can't even identify the min and max of the parameter from plotted points. $\endgroup$
    – kglr
    Dec 5 '21 at 11:15
5
$\begingroup$

Modified an example from the EvaluationMonitor document.

f[s_] = {1 Cos[s], 2 Sin[s]};
{plot, evals2} = 
  Reap[ParametricPlot[f[s], {s, 0, 2 Pi}, 
    EvaluationMonitor :> Sow[{s, f[s]}]]];
evals2
f[s_] = {1 Cos[s], 2 Sin[s]}; {plot, evals} = 
 Reap[Block[{e = 0}, 
   ParametricPlot[f[s], {s, 0, 2 Pi}, 
    EvaluationMonitor :> Sow[Tooltip[Point@f[s], s], ++e]]]];
Show[plot, Graphics[{Red, evals}]]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks! evals only give the plotted points, but not the corresponding parametervalues s ! $\endgroup$ Dec 5 '21 at 11:00
  • $\begingroup$ @UlrichNeumann Show[plot, Graphics[{Red, evals}]] // FullForm or put your mouse in the figure. $\endgroup$
    – cvgmt
    Dec 5 '21 at 11:10
  • $\begingroup$ How would I extract the tooltip values to a separate list? $\endgroup$ Dec 5 '21 at 11:32
  • $\begingroup$ @UlrichNeumann evals2[[1, ;; , 1]] == Cases[FullForm[evals], Tooltip[_, a_] :> a, Infinity] return True $\endgroup$
    – cvgmt
    Dec 5 '21 at 12:14
5
$\begingroup$
f[s_] := {1 Cos[s], 2 Sin[s]}

{plot, slist} = Reap[ParametricPlot[f[Sow@s], {s, 0, 2 Pi}]];

Show[plot, 
 ListLinePlot[f /@ Sort[slist[[1]]], 
  PlotStyle -> Directive[Opacity[.5], CapForm["Butt"], AbsoluteThickness[10],  Red]]]

enter image description here

g[s_] := {Sin[5 s], Sin[4 s]}
{plot, slist} = Reap[ParametricPlot[g[Sow@s], {s, 0, 2 Pi}]];

Show[plot, 
 ListLinePlot[g /@ Sort[slist[[1]]], 
  PlotStyle -> Directive[Opacity[.5], CapForm["Butt"], AbsoluteThickness[10], Red]]]

enter image description here

Update: If we have a Graphics object for a curve generated by ParametricPlot and know only the range of the parameter s, we can use a combination of BSplineFunction, Nearest and Rescale to reconstruct the list of parameter values associated with line coordinates:

{smin, smax} = {0, 2 Pi};

f[s_] := {1 Cos[s], 2 Sin[s]};

plotf = ParametricPlot[f[s], {s, smin, smax}, ImageSize -> 400];

coordsf = Cases[plotf, Line[x_] :> x, All][[1]];

bSFf = BSplineFunction[coordsf];

slistf = Rescale[
  Values @ Association[
    SortBy[Nearest[coordsf][bSFf @ #][[1]] -> # & /@ Subdivide[4000], Last]], 
  {0, 1}, {smin, smax}];

Show[plotf, 
 ListLinePlot[f /@ Sort[slistf], 
  PlotStyle -> Directive[Opacity[.5], CapForm["Butt"], AbsoluteThickness[10], Red]]]

enter image description here

g[s_] := {Sin[5 s], Sin[4 s]}

plotg = ParametricPlot[g[s], {s, smin, smax}, ImageSize -> 400];

coordsg = Cases[plotg, Line[x_] :> x, All][[1]];

bSFg = BSplineFunction[coordsg];

slistg = Rescale[
  Values @ Association[
    SortBy[Nearest[coordsg][bSFg @ #][[1]] -> # & /@ Subdivide[4000], Last]], 
  {0, 1}, {smin, smax}];

Show[plotg, 
 ListLinePlot[g /@ Sort[slistg], 
  PlotStyle -> Directive[Opacity[.5], CapForm["Butt"], AbsoluteThickness[10], Red]]]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ That's it , thank you! Surprisingly slist (* {{0, 0.000128228, s, 0., 0.12333, 0.257035...}} *) starts with symbol s at the third position? $\endgroup$ Dec 5 '21 at 11:55
  • $\begingroup$ @UlrichNeumann, interesting; no idea why s is there. $\endgroup$
    – kglr
    Dec 5 '21 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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