4
$\begingroup$

it doesn't seem the native function NumberLinePlot is able to scale points to reflect coincident points. When an expression such as

Abs[{-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}]

is plotted, the resultant coincident points aren't shown by any metric (such as the size of the point). In such a case, each point would scale the same (except for 0), but there are cases where this isn't so. In cases where multiple plots on the number line might be shown, this relativity might be informative. Is there some way of doing this?

$\endgroup$

2 Answers 2

2
$\begingroup$

You will have to separate your points into groups by whatever criteria is appropriate. Let is suppose, for the purpose of illustration, that there three groups: zero, positive points, negative points. Then they might be rendered on a single line using NumberLinePlot like so:

Module[{zero, pos, neg},
  zero = 0;
  pos = Range[9];
  neg = Range[9];
  NumberLinePlot[
    {zero, neg, pos},
    PlotStyle ->
      {Directive[PointSize[Large], Red],
       Directive[PointSize[Large], Black],
       Directive[PointSize[Tiny], White]},
    Spacings -> None]]

plot

The basic idea is that you use PlotStyle to scale the points and Spacings -> None to put them all one line.

$\endgroup$
2
$\begingroup$
data = RandomInteger[50, 200];

sb = SplitBy[Tally[data] // SortBy[#, Last] &, Last];

NumberLinePlot[Map[First, sb, {2}],
 PlotLegends -> (First /@ Map[Last, sb, {2}]),
 Spacings -> .2,
 AspectRatio -> 1/4]

enter image description here

However. it is easier with ListPlot

ListPlot[GatherBy[Tally[data], Last], AspectRatio -> 1/6]

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.