5

I am trying to plot multiple lists in the same plot in Mathematica (ListLinePlot) and use PlotMarkers and the PlotLegend Package to get the final figure. The issue is that Mathematica puts a marker for every point and this makes it hard to tell which marker is where in the plot. Is it possible to have a plot marker appear every n sample (e.g. every 10 points for a 100 point plot).

The Directive at the moment is PlotMarkers->{Automatic, Small}.

1
  • 1
    I don't know a way to do it with PlotMarkers, could you possibly decimate your dataset to leave only 1 out of every 10 points? Commented Jan 25, 2011 at 2:18

4 Answers 4

4

I think adding something like Mesh->10 should work for you:

data = Accumulate /@ RandomReal[{-1/2, 1}, {3, 100}];
ListLinePlot[data, PlotMarkers -> {Automatic, Small}, Mesh -> 10]

ListLinePlot with a fixed number of plot markers

2
  • 2
    This seems to be the direction, but even in the same example changing the Mesh->10 to Mesh-> 5 or 20 leads to unusual behavior as the markers no longer correspond to the color or shape.
    – o4tlulz
    Commented Jan 25, 2011 at 6:51
  • For example, using the same code but with Mesh -> 9 gives the following plot where (for some reason) only the first plot marker is used everywhere: ifile.it/j8g51q2
    – Simon
    Commented Jan 25, 2011 at 8:50
3

If you want more control over the location of the plot markers than Brett's answer gives you, then you probably have to place the markers manually. Eg (modifying Brett's example)

data = Accumulate /@ RandomReal[{-1/2, 1}, {3, 100}];
col = {Red, Blue, Green};
decimate[i_] := {col[[i]], PointSize -> Medium, 
  Point /@ Transpose[{Range[1, 100, 10], data[[i, 1 ;; -1 ;; 10]]}]}
ListLinePlot[data, PlotStyle -> col, Epilog -> Table[decimate[i], {i, 3}]]

enter image description here

Of course Point can be replaced with any graphics object you want - eg Text, Inset etc...

5
  • You linked to Brett's answer. Yaro answered, but then deleted his contribution. Commented Jan 25, 2011 at 7:45
  • @belisarius: Thanks - I must have got confused! Edited!
    – Simon
    Commented Jan 25, 2011 at 7:51
  • +1 The idea is right there. You could add parameters to decimate[] to fulfill most usual needs. Good one! Commented Jan 25, 2011 at 19:42
  • @belisarius: Yeah, without knowing more about his data (eg if it comes in x,y pairs) and how he'd like to decimate it, there was no point in trying to be too clever in my answer.
    – Simon
    Commented Jan 25, 2011 at 23:07
  • Although it is a rather complicated solution as everything has to be individually selected to match the line it actually works nice and gives absolute control on selecting where to place which marker. Thnx for that.
    – o4tlulz
    Commented Jan 25, 2011 at 23:18
2

Also remember you can use Tooltip to cause the marker coordinates to pop up when you pass the mouse pointer over it:

enter image description here

1

The example of what I was describing in the comment. The markers don't behave properly.

Apparently I cannot post images yet, but running the following code

data = Accumulate /@ RandomReal[{-1/2, 1}, {3, 100}];
ListLinePlot[data, PlotMarkers -> {Automatic, Small}, Mesh -> 5]

should give improper results. Also the number of data and plots in the same figure is quite large to individually select which points and I would like to keep the same Directives for different plots and data ranges as they tend to vary between 100 to around 300 in each case and I have to save them in different tables as they are used in other calculations along the way.

Plot Posted by belisarius, running the code above

enter image description here

10
  • The results of your code seem right to me. Or I am really misunderstanding what you want to achieve, or you should shut down Mma and start a fresh copy and try again. BTW, and just to check, I am going to edit your answer and add the resulting plot, so you can comment what is wrong.. Commented Jan 25, 2011 at 7:51
  • @belisarius: o4tlulz is right. Look at the blue circles in the redish and tan line in you plot. For various values of Mesh -> i it is even worse than that. It's also not fixed by using explicit PlotMarkers. It seems that the Grid and PlotMarkers options do not play nice together....
    – Simon
    Commented Jan 25, 2011 at 8:06
  • @o4tlulz: I think you were referring to my answer in the final paragraph of your "answer" above. As long as you approach to problem programmatically, then you can select the points (say based on the x-value) and put plot markers consistently across all of your plots.
    – Simon
    Commented Jan 25, 2011 at 8:09
  • @Simon, @o4tlulz need to get some sleep now. Please delete this answer after the matter is settled, as this is not a real answer (Although I understand why it has been posted, it should have formally been a comment or an edit to the original question). Tnx Commented Jan 25, 2011 at 8:18
  • @belisarius. I posted as an answer because I thought it would accept the image that I could not post in the comment. Still in the picture you edited the markers do not behave as they are supposed to, they are proper only for two points and this seems to be the case for most of the Mesh->i options.
    – o4tlulz
    Commented Jan 25, 2011 at 8:34

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