3
$\begingroup$

For example ListLinePlot[Range[10000], PlotTheme -> "Monochrome"] will show a marker for every point, how can I show a marker just every hundred points?

$\endgroup$
0
4
$\begingroup$

As of Version 12.1 do not use PlotTheme -> "Monochrome" (see update below)


Taking a sample of the points and then working with Overlay or Show (e.g. mixing ListLinePlot, ListPlot) is a rather cumbersome solution. (Note, that just taking a sample of points, as the quickly accepted answer attempts, will not mark every hundredth point - it simply marks all points in a selection.)

There is a better way to achieve what the OP calls for (e.g. marking a selection of all points) by using Mesh:

SeedRandom["08.01.2019"];
points = RandomVariate[ UniformDistribution[], 50 ];
ListLinePlot[
    points,
    Mesh -> 30, (* setting this to 50-2 = 48 will give all points *)
    PlotTheme -> "Monochrome"
]

ListLinePlot

Playing around with the number of points used for Mesh gives the idea:

enter image description here

So for completeness' sake using Mesh the solution to the OP's problem is approximately:

ListLinePlot[Range[10000], Mesh -> (10000/100), PlotTheme -> "Monochrome"]

UPDATE:

It seems that some things are broken in Version 12.1 as my solution will not work out (@XinBae points out, that earlier Versions had similiar issues).

I found the culprit: It is PlotTheme -> "Monochrome" which seems to break Mesh.

Compare the following output:

SeedRandom["08.01.2019"];
points = Sort@RandomVariate[UniformDistribution[], 50];
GraphicsRow@{
  ListLinePlot[points, Mesh -> 2, PlotTheme -> "Detailed"],
  ListLinePlot[points, Mesh -> 2, PlotTheme -> "Monochrome"]
}

Mesh Problems

$\endgroup$
8
  • $\begingroup$ @xin pei Note, that the topology of the plot is not affected. You called for less "Markers" not less "Points"! $\endgroup$ – gwr Jan 8 '19 at 10:55
  • 1
    $\begingroup$ Yes... Your answer is better $\endgroup$ – XinBae Jan 9 '19 at 2:20
  • $\begingroup$ So why is this answer downvoted? Someone angry because of COVID-19? ;-) $\endgroup$ – gwr May 25 '20 at 18:33
  • 2
    $\begingroup$ Maybe not the COVID-19. This method fails in version 12.1... In fact, in some previous versions, the mesh option also failed @gwr $\endgroup$ – XinBae Jun 2 '20 at 1:06
  • $\begingroup$ @XinBae I see. The culprit is PlotTheme -> "Monochrome" see my update. $\endgroup$ – gwr Jun 2 '20 at 18:05
-1
$\begingroup$

This will do it:

ListLinePlot[Range[10000][[1;;-1;;100]], PlotTheme -> "Monochrome"]

The [[1;;-1;;100]] part specification picks one element every 100 elements.

$\endgroup$
7
  • $\begingroup$ Yes, it is. This will work for any list. $\endgroup$ – mmeent Jan 8 '19 at 8:13
  • 2
    $\begingroup$ OP wants less marks but not less points. $\endgroup$ – gwr Jan 8 '19 at 8:17
  • $\begingroup$ @gwr You can always make two plots and combine them with Show - one ListLinePlot without markers, and one ListPlot employing this solution to get a marker every 100 points $\endgroup$ – Lukas Lang Jan 8 '19 at 8:18
  • 1
    $\begingroup$ @gwr What I meant is that you make the ListLinePlot with all data points, and only the ListPlot with the subset. Or do you mean something else? $\endgroup$ – Lukas Lang Jan 8 '19 at 8:25
  • 1
    $\begingroup$ @LukasLang I am saying, that your suggestion will work but I am addressing this answer and it will not work in general. That is all. $\endgroup$ – gwr Jan 8 '19 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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