7
$\begingroup$

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!

$\endgroup$
11
  • $\begingroup$ Regarding the first question you could create two plots, one with the ListLinePlot with all the data, the second would be a ListPlot with the desired number of data (e.g. each 2) with PlotMarkers. Then Show would make it fit :) $\endgroup$
    – Öskå
    Jun 11, 2014 at 21:37
  • $\begingroup$ Regarding the second question, I think this should help. $\endgroup$
    – Öskå
    Jun 11, 2014 at 21:38
  • $\begingroup$ @Öskå Thanks for your replies. Let me try! $\endgroup$
    – O_o
    Jun 11, 2014 at 21:41
  • $\begingroup$ @Öskå, your first answer works, but how can I handle the PlotLegends in this case? $\endgroup$
    – O_o
    Jun 11, 2014 at 21:54
  • $\begingroup$ I don't have v9 so I don't know much about PlotLegends. Does Show remove it? $\endgroup$
    – Öskå
    Jun 11, 2014 at 21:59

3 Answers 3

6
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ You can do both at once with something like Point[x:{__Integer}]:> Map[Inset["■", #] &, x[[;;;;5]]] (+1) $\endgroup$
    – kglr
    Jun 11, 2014 at 23:20
  • $\begingroup$ @Ö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. $\endgroup$
    – O_o
    Jun 14, 2014 at 19:53
5
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ That's much better indeed :) $\endgroup$
    – Öskå
    Jun 12, 2014 at 8:53
  • $\begingroup$ @kguler, Thank you. I am trying to do it for multiple data lists and include legends as well. I will comment if I fail. $\endgroup$
    – O_o
    Jun 12, 2014 at 9:56
3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ @Öska - please change ListPlott (I tried to edit, but you have to change more than just one character). $\endgroup$
    – eldo
    Jun 11, 2014 at 22:08
  • $\begingroup$ I did sorry :) I just noticed.. :) $\endgroup$
    – Öskå
    Jun 11, 2014 at 22:08
  • $\begingroup$ @eldo Thank you. I should change it a little for multiple plots with legends. $\endgroup$
    – O_o
    Jun 11, 2014 at 22:08

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.