7
$\begingroup$

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}]
$\endgroup$
7
  • $\begingroup$ @Öskå yeah that's why I'm asking $\endgroup$
    – user0322
    Commented Jun 11, 2014 at 15:06
  • $\begingroup$ @Öskå i'd like to use PlotMarkers->{"■"} on it. $\endgroup$
    – user0322
    Commented Jun 11, 2014 at 15:11
  • $\begingroup$ @Ö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] $\endgroup$
    – user0322
    Commented Jun 11, 2014 at 15:20
  • 1
    $\begingroup$ 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? $\endgroup$
    – Mr.Wizard
    Commented Jun 11, 2014 at 15:24
  • 1
    $\begingroup$ Related question $\endgroup$
    – m_goldberg
    Commented Jun 11, 2014 at 16:18

6 Answers 6

9
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – eldo
    Commented Jun 11, 2014 at 20:42
  • $\begingroup$ @eldo For even spacing read this: (8454) $\endgroup$
    – Mr.Wizard
    Commented Jun 11, 2014 at 20:57
  • $\begingroup$ Thanks for this must-read. I'll try it tomorrow with the "eight". $\endgroup$
    – eldo
    Commented Jun 11, 2014 at 21:26
6
$\begingroup$
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

$\endgroup$
1
  • $\begingroup$ Another very nice solution. I didn't know about this syntax. $\endgroup$
    – Mr.Wizard
    Commented Jun 12, 2014 at 4:06
6
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ Except the marker style you would get the same result using the shorter code below :) $\endgroup$
    – eldo
    Commented Jun 17, 2014 at 15:39
  • 1
    $\begingroup$ @eldo This approach does not require analytically differentiating the function. I guess I should have said that, but it is in the link. $\endgroup$
    – george2079
    Commented Jun 17, 2014 at 16:00
  • $\begingroup$ understood, thank you $\endgroup$
    – eldo
    Commented Jun 17, 2014 at 16:18
5
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Very nice! That's far more direct. +1 $\endgroup$
    – Mr.Wizard
    Commented Jun 12, 2014 at 4:05
3
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ +1 - I particularly like this markers = Graphics`PlotMarkers[]. Never saw it before. $\endgroup$
    – eldo
    Commented Jun 13, 2014 at 20:46
3
$\begingroup$

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

$\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.