3
$\begingroup$

Suppose the following line segments:

2<x<5 
0<x<3 
1<x<6

I would like to somehow see a plot of those line segments. Preferably vertically, stacked in the order of occurrence in the original list.

Prefer to use Mathematica.

I tried:

Plot[2 < x < 5, {x, 0, 7}]

...and am not even able to see the line segment requested.

If I could at least see the line segment (perhaps thick and colored?), I could go another round subsequently for each additional line segment, three different plots, and view and compare the relative lengths of the line segments stacked one upon the other. Then perhaps send all to a .pdf file for later viewing.

One single plot would be the ideal. Using the above approach the line segments would overlap each other. Which would be useless. I would have to create three different plots, one after the next.

Any suggestions appreciated.

Nicholas Kormanik

$\endgroup$
1
  • 3
    $\begingroup$ Look at NumberLinePlot $\endgroup$
    – Chris
    Commented Jan 3, 2020 at 0:39

2 Answers 2

5
$\begingroup$
NumberLinePlot[{2 < x < 5, 0 < x < 3, 1 < x < 6}, x,
 PlotLegends -> "Expressions",
 PlotStyle -> Directive[Thickness[.01], PointSize -> Large]]

enter image description here

$\endgroup$
4
$\begingroup$
ineqs = {2 < x < 5, 0 < x < 3, 1 < x < 6};

funcs = MapIndexed[ConditionalExpression[#2[[1]], #] &, ineqs];

Plot[funcs, {x, 0, 7}, Frame -> True, 
 FrameTicks -> {{Thread[{Range@3, HoldForm /@ ineqs}], Automatic}, {Automatic, Automatic}}, 
 PlotLegends -> ineqs]

enter image description here

epilog = MapIndexed[Text[Style[#, 16], {Mean[{#, #3}] & @@ #, #2[[1]]}] &, ineqs];

Plot[funcs, {x, 0, 7}, 
 Frame -> True, 
 PlotStyle -> Directive[CapForm["Round"], AbsoluteThickness[30]], 
 FrameTicks -> {{None, None}, {Automatic, Automatic}}, 
 Epilog -> epilog, PlotLegends -> ineqs, 
 PlotRangePadding -> Scaled[.2], 
 Axes -> False, 
 AspectRatio -> 1/3]

enter image description here

Replace CapForm["Round"] with CapForm["Butt"] to get

enter image description here

$\endgroup$
1
  • $\begingroup$ Beautiful work Rohit Namjoshi and kglr. Thanks very much for your help! $\endgroup$
    – nkormanik
    Commented Jan 6, 2020 at 8:47

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.