1
$\begingroup$

In Wolfram, how can one create a plot similar to the following:

enter image description here

That is: a number-line like continuum with labeled points?

$\endgroup$
4
$\begingroup$
SeedRandom[77]
lst = RandomSample[Range[-10, 10, .25], 5];

ListPlot[MapThread[{Callout[#, Rotate[#[[1]], 90 Degree], Above, 
          LeaderSize -> 30, LabelStyle -> Directive[#2, 12], 
          CalloutMarker -> "Arrow", "CalloutStyle" -> #2]} &,
     {Thread[{lst, 0}], ColorData[97] /@ Range[Length@lst]}], 
   PlotStyle -> PointSize[.015], Axes -> {True, False}, 
   Ticks -> {Range[-10, 10], None}, 
   PlotRange -> {{-10, 10}, Automatic},
   PlotRangePadding -> Scaled[.1],
   AxesStyle -> Arrowheads[{{-.05, 0}, {.05, 1}}]]

enter image description here

Update: Using custom Arrowheads to label the two directions of horizontal axis:

ListPlot[MapThread[{Callout[#, Rotate[#[[1]], 90 Degree], Above, 
     LeaderSize -> 30, LabelStyle -> Directive[#2, 12], 
     CalloutMarker -> "Arrow", "CalloutStyle" -> #2]} &,
   {Thread[{lst, 0}], ColorData[97] /@ Range[Length@lst]}], 
  PlotStyle -> PointSize[.015], Axes -> {True, False}, 
  Ticks -> {Range[-10, 10], None}, 
  PlotRange -> {{-10, 10}, Automatic},
  AxesStyle -> Arrowheads[{{-.05, 0}, {.05, 1},
     {.05, 0,  Graphics @ Text[Style["negative direction", 16], {0, 0}, {1., 0}]}, 
     {.05, 1, Graphics @ Text[Style["positive direction", 16], {0, 0}, {-1.1, 0}]}}], 
  PlotRangePadding -> Scaled[.1], 
  ImagePadding -> {{Scaled[.15], Scaled[.15]}, {None, Scaled[.05]}}, 
  ImageSize -> 700]

enter image description here

Alternatively, add the axes labels using Epilog:

ListPlot[MapThread[{Callout[#, Rotate[#[[1]], 90 Degree], Above, 
     LeaderSize -> 30, LabelStyle -> Directive[#2, 12], 
     CalloutMarker -> "Arrow", "CalloutStyle" -> #2]} &, 
    {Thread[{lst,  0}], ColorData[97] /@ Range[Length@lst]}], 
  PlotStyle -> PointSize[.015], Axes -> {True, False}, 
  Ticks -> {Range[-10, 10], None}, 
  PlotRange -> {{-10, 10}, Automatic},
  AxesStyle -> Arrowheads[{{-.05, 0}, {.05, 1}}], 
  PlotRangePadding -> Scaled[.1], 
  ImagePadding -> {{Scaled[.2], Scaled[.2]}, {None, Scaled[.05]}}, 
  ImageSize -> 700, 
  Epilog -> {Text[Style["negative direction", 16], Offset[{-30, 0}, {-11, 0}], {1, 0}] , 
   Text[Style["positive direction", 16], Offset[{30, 0}, {11, 0}], {-1, 0}]}]

enter image description here

$\endgroup$
  • $\begingroup$ Is there a way to label the arrow heads on both side of the plot (i.e., the left one "negative direction" and the right one perhaps "positive direction")? $\endgroup$ – George Aug 5 at 18:09
  • $\begingroup$ @George, please see the update. $\endgroup$ – kglr Aug 5 at 18:53
  • $\begingroup$ The second method (using Epilog) doesn't work on my local version of Wolfram Desktop (I just see the number line w/o any text). Is this also the case on your machine? $\endgroup$ – George Aug 10 at 3:49
  • $\begingroup$ @George, I don't have the desktop version of v12. The pictures I posted are obtained using v12 on Wolfram Cloud. $\endgroup$ – kglr Aug 10 at 4:11
  • $\begingroup$ This is what I"m seeing. $\endgroup$ – George Aug 10 at 14:00

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.