Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}]
share|improve this question
    
@Öskå yeah that's why I'm asking –  Herman Jun 11 at 15:06
    
@Öskå i'd like to use PlotMarkers->{"■"} on it. –  Herman Jun 11 at 15:11
    
@Öskå this one but I'd like to use PlotMarkers->{"■"} Epilog -> {Red, PointSize[Large],Point[{f(x), g(x)}, AspectRatio -> 1, PlotStyle -> Thick, PlotRange -> All, ImageSize -> Medium] –  Herman Jun 11 at 15:20
    
Herman, the point is that PlotMarkers is not an Option for ParametricPlot: MemberQ[Options[ParametricPlot], PlotMarkers -> _] is False. You cannot use it unless you use a modified definition for ParametricPlot. Presumably you are asking for behavior akin to PlotMarkers; is that correct? –  Mr.Wizard Jun 11 at 15:24
1  
Related question –  m_goldberg Jun 11 at 16:18

6 Answers 6

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.

share|improve this answer
    
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 at 20:42
    
@eldo For even spacing read this: (8454) –  Mr.Wizard Jun 11 at 20:57
    
Thanks for this must-read. I'll try it tomorrow with the "eight". –  eldo Jun 11 at 21:26
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

share|improve this answer
    
Another very nice solution. I didn't know about this syntax. –  Mr.Wizard Jun 12 at 4:06

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

share|improve this answer
    
Very nice! That's far more direct. +1 –  Mr.Wizard Jun 12 at 4:05
    
Thank you @Mr.W. –  kguler Jun 12 at 22:50

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

share|improve this answer
    
Except the marker style you would get the same result using the shorter code below :) –  eldo Jun 17 at 15:39
1  
@eldo This approach does not require analytically differentiating the function. I guess I should have said that, but it is in the link. –  george2079 Jun 17 at 16:00
    
understood, thank you –  eldo Jun 17 at 16:18

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

share|improve this answer

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

share|improve this answer
    
+1 - I particularly like this markers = Graphics`PlotMarkers[]. Never saw it before. –  eldo Jun 13 at 20:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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