7

Two questions, but I am not sure whether they are already answered or not.

  • How can I create PlotMarkers (in ListLinePlot) with less points (less markers)? Or markers with some intervals. I have tried the Mesh option, but it does not work; it messes up all the plots.

  • Is it possible to create PlotMarkers for normal Plot, not ListPlot? One way is to export the data to the list, but I would like to do it directly.

More information: Suppose ListLinePlot of a number of data lists with legends. based on the suggestions, I have changed my plots into this, but honestly I cannot understand how it works!

style = Sequence @@ {Frame -> {{True, False}, {True, False}}, 
   FrameTicks -> {{0, 1, 2, 3}, {0, 0.4, 0.8, 1.5}, None, None}, 
   FrameStyle -> Directive[Black, 16, FontSlant -> Plain], 
   LabelStyle -> Directive[FontSlant -> Plain], 
   AxesStyle -> Lighter@Gray, TicksStyle -> Black, 
   LabelStyle -> {GrayLevel[0], 14, FontSlant -> Plain, 
     FontFamily -> "Helvetica"}, ImageSize -> 300, 
   AspectRatio -> 1/GoldenRatio}

  ListLinePlot[{c1, c2, c3, c4}, PlotRange -> Full, 
  Evaluate@style, 
  PlotLegends -> Placed[{Long, S_Short, Short, Flexible}, Below], 
  PlotStyle -> (Directive[
       AbsoluteThickness[2], #] & /@ (ColorData[81] /@ Range[6])), 
  MeshFunctions -> {Abs[#1] &, Abs[#1] &, Abs[#1] &, Abs[#1] &}, 
  Mesh -> 6, PlotMarkers -> {Automatic, 20}, 
  MeshStyle -> {ColorData[81] /@ Range[6], ColorData[81] /@ Range[7], 
    ColorData[81] /@ Range[8], ColorData[81] /@ Range[9]}]

The output is something like this, where as you can see each Markers has all the colours together. How can I solve this problem and improve it? Another problem is the distribution of the Markers which is not good.

the output!

O_o
  • 259
  • 1
  • 9

3 Answers3

6

First question if you don't want to play with Mesh you could do:

data = Thread@{Range@10, Range[1, 100, 10]}
llp = ListLinePlot[data];
lp[n_] := ListPlot[data[[1 ;; Length@data ;; n]], PlotMarkers -> Automatic];
Table[Show[llp, lp@i], {i, 1, 10, 2}]

enter image description here

Second question:

Eldo's answer or Mr.Wizard's answer:

Plot[x, {x, 1, 10}, Mesh -> 5] /. 
 Point[x : {__Integer}] :> Map[Inset["■", #] &, x]

Mathematica graphics

Öskå
  • 8,587
  • 4
  • 30
  • 49
  • You can do both at once with something like Point[x:{__Integer}]:> Map[Inset["■", #] &, x[[;;;;5]]] (+1) – kglr Jun 11 '14 at 23:20
  • @Öskå, I could not solve the problem so I used your idea of combining two plots together. Thank you and the other for your help. – O_o Jun 14 '14 at 19:53
5

MeshStyle option setting can be a function, so you can use that function to reduce the number of mesh points and to specify the markers:

Row[{Plot[x, {x, 1, 10}, Mesh -> 20, ImageSize -> 400, MeshStyle -> Red],
     Plot[x, {x, 1, 10}, Mesh -> 20, ImageSize -> 400, 
       MeshStyle -> 
        (Map[Inset[Style["\[FilledSquare]", Red, 36], #] &, #[[;; ;; 4]]] & @@ ## &)]},
 Spacer[5]]

enter image description here

One can use the same trick with ListLinePlot:

data = Thread@{Range@10, Range[1, 100, 10]};
Row[{ListLinePlot[data, Mesh -> All, ImageSize -> 400, MeshStyle -> Red],
   ListLinePlot[data, Mesh -> All, ImageSize -> 400, 
    MeshStyle -> 
      (Map[Inset[Style["\[FilledSquare]", Blue, 16], #] &, #[[;; ;;3]]] & @@ ## &)]}, 
 Spacer[5]]

enter image description here

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

Regarding the second part of your question:

Plot[Sin[x], {x, 0, 2 Pi}, Mesh -> {Range[0, 2 Pi, Pi/4]}, 
 MeshStyle -> PointSize[Medium]]

enter image description here

Plot[Sin[x], {x, 0, 2 Pi}, Mesh -> {Range[0, 2 Pi, Pi/8]}, 
 MeshStyle -> PointSize[Medium]]

enter image description here

As to the first part of your question: Follow the link provided by Öska.

eldo
  • 67,911
  • 5
  • 60
  • 168