2
$\begingroup$

I use this code

list :=  {Interval[{ 1 , 1.5  }], Interval[{ 3.9 , 5.1 }], Interval[{ 5.7 ,6.7 }], Interval[{ 7.5 , 9.8 }] } ;

NumberLinePlot[list, Spacings -> Prepend[0.2]@ConstantArray[.0, Length@list], PlotStyle -> Directive[Black, Thickness[0.001]]]

and I get this plot

enter image description here

Question:

Is it possible to change the endpoints marker from "solid points" to "small vertical line"? something like this picture

enter image description here

Any comments are appreciated.

$\endgroup$
1
  • 2
    $\begingroup$ NumberLinePlot[list, Spacings -> Prepend[0.2]@ConstantArray[.0, Length@list], PlotStyle -> Directive[Black, Thickness[0.001]]] /. Point[{x_, y_}] :> Line[{{x, y - 0.03}, {x, y + 0.03}}] $\endgroup$
    – Bob Hanlon
    Feb 8, 2022 at 4:39

1 Answer 1

3
$\begingroup$
verticalLine[voffset_: 3] := Line[Table[Offset[{0, voffset i}, #], {i, {-1, 1}}]] &

displayF[voffset_: 3] := ReplaceAll[wp : {White, ___, _Point} :> 
      (wp /. Point -> verticalLine[voffset/4]), 
    Point -> verticalLine[voffset]}];

Examples:

list := {Interval[{1, 1.5}], Interval[{3.9, 5.1}], 
   Interval[{5.7, 6.7}], Interval[{7.5, 9.8}]};

NumberLinePlot[list, 
 Spacings -> Prepend[0.2] @ ConstantArray[.0, Length @ list], 
 PlotStyle -> Directive[Black, Thickness[0.001]], 
 DisplayFunction -> displayF[]]

enter image description here

An example with half-open intervals:

nlp = NumberLinePlot[{Sin[x] < Cos[x], Sin[x] > Cos[x], 1 < x <= 3}, {x, 0, 2 Pi}, 
  PlotStyle -> Directive[AbsoluteThickness[3], AbsolutePointSize[10]], 
  ImageSize -> Large]

enter image description here

Show[nlp, DisplayFunction -> displayF[7]]

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.