7

I have a parametric plot, and would like to fit a line to it with "■" PlotMarkers on it, but am unable to do so.

ParametricPlot[{f(x), g(x)}, {x, 0, 1}, AxesLabel -> {"x", "y"}, PlotMarkers->{"■", 10.9}]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user0322
  • 425
  • 2
  • 14

6 Answers6

9

You can add plot markers by manipulating the Graphics output of ParametricPlot.

marker = Style["\[FilledDiamond]", FontSize -> 10.88];

ParametricPlot[{Sin[u], Sin[2 u]}, {u, 0, 2 Pi}, Mesh -> 50] /.
  Point[x : {__Integer}] :> Map[Inset[marker, #] &, x]

enter image description here

To put markers of different styles on multiple lines is more complicated but I will try to solve that later.


I couldn't think of any clever way to do multiple markers at once so here's the blunt way:

plot[fn_, mk_, sty_] :=
  ParametricPlot[fn, {t, 0, 2 Pi}, PlotStyle -> sty, Mesh -> 30] /. 
   Point[x : {__Integer}] :> {sty, Map[Inset[mk, #] &, x]}

MapThread[plot,
  {
   {{2 Cos[t], Sin[t]}, {Cos[t], 2 Sin[t]}, {Cos[t], Sin[t]}},
   Style[#, FontSize -> 10.88] & /@ {"\[FilledDiamond]", "\[FilledSquare]", "\[Wolf]"},
   {Red, Green, Blue}
  }
] // Show[#, PlotRange -> All] &

enter image description here

Note: I did not bother to localize t because I don't expect you to use this code as-is. Wrap everything in Block[{t}, . . . ] if you wish. Hopefully someone else has a cleaner approach to the whole problem.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • Wizard - Looking at your first example, the figure eight, I would like to observe that the markers are unpleasantly arranged by Mathematica. (Look at the 4 points around [0,0]). This missing symmetry would become even worse in my answer. Tried to find a solution to this during the last hour, but to no avail. – eldo Jun 11 '14 at 20:42
  • @eldo For even spacing read this: (8454) – Mr.Wizard Jun 11 '14 at 20:57
  • Thanks for this must-read. I'll try it tomorrow with the "eight". – eldo Jun 11 '14 at 21:26
6
f[x_] = x Cos[x];
g[x_] = x Sin[x];

ParametricPlot[{f[x], g[x]}, {x, 0, 4 Pi}, AxesLabel -> {"x", "y"}, Mesh -> {{#, 
  Text[Style["\[FilledSquare]", Red, 10.9], {f[#], g[#]}]} & /@ 
  Range[0, 4 Pi, Pi/8]}]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
6

Nice evenly spaced points

 marker = Graphics`PlotMarkers[][[4, 1]]
 ListLinePlot[
     t = Table[{u Cos[u], u Sin[u]} // N, {u, 0, 4 Pi, 4 Pi/1000}], 
     AspectRatio -> 1/GoldenRatio, 
     Epilog -> (Text[Style[marker, Blue, 10.9], #] & /@ (linepoints[t, 30]) )]

with linepoints from here : Is it Possible to change dashes into circles with Plot command?

enter image description here

or if you want to use ParametricPlot:

 marker = Graphics`PlotMarkers[][[4, 1]];
 t = Table[{u Cos[u], u Sin[u]} // N, {u, 0, 4 Pi, 4 Pi/1000}];
 ParametricPlot[{u Cos[u], u Sin[u]} // N, {u, 0, 4 Pi}, 
        Epilog -> (Text[Style[marker, Blue, 10.9], #] & /@ (linepoints[t,30]) )]

Edit: modified the interpolation to return the arc length parameter to work with Mesh :

 linepointsP[plist_, n_] := Module[{},
        arc = Interpolation[(Transpose@{{0}~Join~
               Accumulate@(Norm@(Subtract @@ #) & /@ Partition[plist, 2, 1]),
                   N@Range[0, Length[plist] - 1]/(Length[plist] - 1)}), 
              InterpolationOrder -> 3];
        tlen = Last@First@First@(arc);
        Table[arc[tlen iz/n], {iz, 0, n}]];
  marker = Graphics`PlotMarkers[][[4, 1]];
  {umin, umax} = {.1, 10 Pi};
  g[u_] :=  (u/umax)^(5) {  Cos[u], Sin[u]};
  nmarkers=100;
  ndis = 1000; (* # points adequate to create a good cubit interpolation function *)
  ParametricPlot[g[u], {u, umin, umax} ,
         Mesh -> {(umin + (umax - umin ) #) & /@ 
           linepointsP[Table[g[u], {u, umin, umax, (umax - umin)/ndis}], 
         nmarkers]  },
          MeshStyle -> (Map[
                Inset[Style[marker, Green, 12], #] &, #] & @@ ## &), 
            PlotRange -> All]

enter image description here

george2079
  • 38,913
  • 1
  • 43
  • 110
5

Update: For multiple functions, we can use the MeshStyle trick on each one separately and combine the results using Show:

funcs = {{2 Cos[t], 2 Sin[t]}, {2 Cos[t], Sin[t]}, 
         {Sin[t] Cos[t], 2 Sin[t]}, {Cos[t], Cos[t] Sin[t]}};
mesh = {50, 30, 40, 20};
colors = ColorData[1, "ColorList"][[;; 4]];
markers = {"◆", "■",  "▲", "◇"};

Show[Module[{ins = Style[#4, #3, 16]}, 
    ParametricPlot[#, {t, 0, 2 Pi}, Mesh -> #2, PlotStyle -> #3, 
    MeshStyle -> (Function[w, Map[Function[z, Inset[ins, z]], w]] @@ ## &)]] & @@@ 
  Transpose[{funcs, mesh, colors, markers}]]

enter image description here

Original answer:

You can also use MeshStyle as follows:

ParametricPlot[{Sin[u], Sin[2 u]}, {u, 0, 2 Pi}, Mesh -> 50,
  MeshStyle -> (Map[Inset[Style["\[FilledDiamond]", Blue, 16], #] &, #] & @@ ## &)]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
3

I've been thinking all day about the wonderful solutions (by @Mr.Wizard, @eldo, @Bob Hanlon and @kguler) and would like to show my approach. One can find the PlotMarkers with the command

markers = Graphics`PlotMarkers[]

enter image description here

And also assign them, i.e. stripping List of Lists;

m1 = markers[[All, 1]]

enter image description here

The following was pretty easy

p1 = ListPlot[Table[{Sin[n], Sin[4 n]}, {n, 6 \[Pi]}], 
  PlotStyle -> {Red}, PlotMarkers -> {m1[[2]]}];
p2 = ParametricPlot[{Sin[u], Sin[4 u]}, {u, 0, 2 Pi}]

Show[p2, p1]

enter image description here

  • +1 - I particularly like this markers = Graphics`PlotMarkers[]. Never saw it before. – eldo Jun 13 '14 at 20:46
3

Thanks to Szabolcs solution in link I can now plot symmetric points:

eight := {Cos[t], Sin[2 t]}
lim = 2 Pi;

Off[FunctionInterpolation::ncvb]

velocity = FunctionInterpolation[Evaluate@Norm@D[eight, t], {t, 0, lim}];
arclength = Derivative[-1][velocity];
inverse = InverseFunction[arclength];

points = eight /. t -> # & /@ 
   Table[inverse[x], {x, 0, arclength[lim], arclength[lim]/20}];

Show[ParametricPlot[eight, {t, 0, lim}, PlotStyle -> Black], 
 ListPlot[points, PlotStyle -> Directive[PointSize[0.02], Red]]]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168