I have a parametric plot showing a path of an object in x and y (position), where each is a function of t (time), on which I would like to put a time tick, every second let's say. This would be to indicate where the object is moving fast (widely spaced ticks) or slow (closely spaced ticks). Each tick would just be short line that crosses the plot at that point in time, where that short line is normal to the plotted curve at that location.

I'm sure I can figure out a way to do it using lots of calculations and graphics primitives, but I'm wondering if there is something built-in that I have missed in the documentation that would make this easier.

(Note: this is about ticks on the plotted curve itself -- this doesn't have anything to do with the ticks on the axes or frame.)

  • 2
    $\begingroup$ As an option to your plot, try Mesh -> 50 $\endgroup$ – wxffles Jul 24 '12 at 23:03
  • $\begingroup$ Thanks. Mesh gets close to what I want. If the parametric plot range is {t,a,b}, then it appears I can use Mesh->Round[(b-a)/10] to get dots every 10 seconds. (Obviously it works best if b-a is a multiple of 10.) Now I need to figure out how to turn those into perpendicular line segments. I see that I can set Mesh to a list of tick locations each with a graphics directive ... $\endgroup$ – Mark Adler Jul 24 '12 at 23:15

To create the ticks perpendicular to the curve, I calculate the direction of the normal to the curve where the ticks are to be placed and then orient a line segment along that direction. The following code does that.

SetAttributes[ParametricTimePlot, HoldAll]
ParametricTimePlot[fun_, {var_, min_, max_, steps_}, len_, 
    opts : OptionsPattern[]] := 
        ParametricPlot[fun, {var, min, max}, opts],
            Rotate[Translate[Line[{{-len/2, 0}, {len/2, 0}}], #1], ArcTan @@ #2]
        ] & @@@ (N@Table[{fun, RotationMatrix[π/2].D[fun, var]} /. var -> i, 
            {i, min + steps, max, steps}])

Use the above function as:

ParametricTimePlot[{ Sqrt[t] Cos[t], Sqrt[t] Sin[t]}, {t, 0, 2 π, 
    π/10}, 0.1, PlotStyle -> Blue]

enter image description here

If you want to keep it simple and just show the dots, then this is very straightforward:

SetAttributes[ParametricTimePlot, HoldAll]
ParametricTimePlot[fun_, {var_, min_, max_, steps_}, opts : OptionsPattern[]] :=     
    ParametricPlot[fun, {var, min, max}, opts] 
    ListPlot[Table[fun /. var -> i, {i, min, max, steps}], 
        PlotStyle -> Red, PlotMarkers -> {Automatic, 8}]

ParametricTimePlot[{ Sqrt[t] Cos[t], Sqrt[t] Sin[t]}, {t, 0, 2 Pi, Pi/10}, 
    PlotStyle -> Blue]

enter image description here

  • 1
    $\begingroup$ There's a more compact way to do your second routine. Witness ParametricPlot[{Sqrt[t] Cos[t], Sqrt[t] Sin[t]}, {t, 0, 2 Pi}, Mesh -> {Range[0, 2 Pi, Pi/10]}, MeshStyle -> Directive[AbsolutePointSize[5], Red], PlotStyle -> Blue]. $\endgroup$ – J. M. will be back soon Jul 24 '12 at 23:36
  • $\begingroup$ @MarkAdler Could you add an example of the functions you're plotting? $\endgroup$ – rm -rf Jul 24 '12 at 23:40
  • $\begingroup$ @J.M. Yes, I noticed wxffles' comment after I'd written it. Will fix in the next edit $\endgroup$ – rm -rf Jul 24 '12 at 23:40
  • $\begingroup$ @MarkAdler Are your functions smooth or at least, differentiable once? $\endgroup$ – rm -rf Jul 24 '12 at 23:42
  • $\begingroup$ Ah, my mistake. Your ParametricTimePlot with line segment ticks is working perfectly with my interpolating functions. Thanks! $\endgroup$ – Mark Adler Jul 24 '12 at 23:52

One way to do it would be to find analytically the parallel line yourself, and then creating a Graphics[] with all the lines. Here is a rough working example that's specific to this one expression and scales the lines according to the differential of the function, but it outlines the gist of the idea.

Line /@ Table[
     {Cos[t^2], Sin[t^2]} + 
        (0.1/2 tickpoint D[{Cos[t^2], Sin[t^2]}, t] // {#[[2]], -#[[1]]} &)
, {t, 0, 2.5, 0.05}, {tickpoint, {-1, 1}}] // Graphics,
ParametricPlot[{Cos[t^2], Sin[t^2]}, {t, 0, 2.5}]

ParametricPlot combined with ticks showing regular intervals of the parameter


I couln't get nice little lines so I've used filled circles instead. I hope this works.

I've spaced the points out but Pi/4 on the curve in this example.

f = {Sin[#], Sin[2 #]} &
 ParametricPlot[f[u], {u, 0, 2 \[Pi]}],
 ListPlot[f /@ Range[0, 2 \[Pi], \[Pi]/4], 
  PlotStyle -> Directive[PointSize[0.02], Black]]

"Mathematica graphic"


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.