0
$\begingroup$

I have a table in the following format: Apple 2 Pear 3 Banana 5 Orange 6.5 .... I would like to put the values on a single horizontal axis and add corresponding descriptive labels (apple, pear, banana etc.) next to the values. How can I do that in Mathematica? Many thanks!

$\endgroup$
  • $\begingroup$ You may want to look up BarChart. $\endgroup$ – Jens Jul 2 '13 at 5:26
  • $\begingroup$ What do you mean by put the values on a single horizontal axis? It sound like you want a dot on a line with a label. That's not the BarChart Jens suggested. Could you be a little bit more specific? $\endgroup$ – Sjoerd C. de Vries Jul 2 '13 at 5:48
5
$\begingroup$

From a list like ls = {{"Apple", 2} , {"Pear", 3}, {"Banana", 5}, {"Orange", 6.5}} you can get:

ListPlot[Labeled[{#[[2]], 0},Framed[Rotate[#[[1]], 90 Degree],
Background -> Yellow], Top] & /@ ls, Axes -> {True, False}]

Result

$\endgroup$
0
$\begingroup$

Another possibility is to do it yourself:

ls = {{"Apple", 2}, {"Pear", 3}, {"Banana", 5}, {"Orange", 6.5}};
Graphics[{
  {Text[Style[First@#, 18], {Last@#, 0.25}],
     Red,
     Disk[{Last@#, 0.1}, .05]} & /@ ls,
  },
 Axes -> { True, False}]

single axis diagram

$\endgroup$
0
$\begingroup$

Using ListPlot with Callout:

ls = {{"Apple", 2} , {"Pear", 3}, {"Banana", 5}, {"Orange", 6.5}};

ListPlot[Callout[{#2, 0}, #, Above, 
    Background -> LightOrange, Frame -> True, FrameMargins -> 6, 
    "CalloutStyle" -> Red, LeaderSize -> 30, 
    LabelStyle -> {14, Bold, Red}, 
    CalloutMarker -> Arrowheads[.05]] & @@@ ls, Axes -> {True, False},
  PlotStyle -> PointSize[Large], AspectRatio -> (1/4)]

enter image description here

(Ab)using TimelinePlot:

TimelinePlot[Labeled[{2000, 1, 1, #2}, # ] & @@@ ls, DateTicksFormat -> {"HourShort"}]

enter image description here

$\endgroup$

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.