# How to place rotated text labels on a discrete plot

I'm trying to create a discrete plot with horizontal tick labels consisting of specified text. Here's a simple example:

X={2,3,4,5}
DiscretePlot[X[[k]], {k, 1, 4}]


My labels are stored in a list:

labels={bob,ted,carol,alice}


I'd like to know what options added to the DiscretePlot command will yield a result in which the label names appear along the horizontal axis, with each name appearing under the corresponding segment in the plot. Because I'll eventually have names of longer length, I'd also like to rotate the name labels a specified amount, e.g. 45 degrees.

• – ktm
Feb 23, 2017 at 21:30

xx = {2, 3, 4, 5};
labels = {bob, ted, carol, alice};

DiscretePlot[xx[[k]], {k, 1, 4},
PlotRange -> {{0, 5}, {0, Automatic}}, ImagePadding -> 55,
Ticks->{Transpose[{Range@4, Column /@ Transpose[{Range@4, Rotate[#, Pi/2]& /@ labels}]}],
Automatic}] Update: Alternatively, use Epilog or Prolog:

lp = ListPlot[List /@ Thread[{Range@Length@xx, -1/2}],
PlotStyle -> Directive[{Black, FontSize -> 14}],
PlotMarkers -> (Rotate[ToString@#, Pi/4] & /@ labels)];

DiscretePlot[xx[[k]], {k, 1, 4},
PlotRange -> {{0, 5}, {0, Automatic}}, Filling -> Axis,
ImagePadding -> {{Automatic, Automatic}, {100, Automatic}},
Epilog -> lp[]] I believe this is what you're after:

X = {2, 3, 4, 5};
DiscretePlot[X[[k]], {k, 1, 4},
Ticks -> {{{1, Rotate["Bob", 45]}, {2, Rotate["Ted", 45]}, {3,
Rotate["Carol", 45]}, {4, Rotate["Alice", 45]}}, Automatic},
PlotRange -> {{0, 5}, Automatic}]


Notice the use of the Ticks option with the Rotate wrapper. Edit: Or even something like this if you want to maintain the tick's number as well:

labels = {"bob", "ted", "carol", "alice"};
rotatedLabels =
MapThread[{#1, Column[{#1, Rotate[#2, Pi/2]}]} &, {Range, labels}]

X = {2, 3, 4, 5};
DiscretePlot[X[[k]], {k, 1, 4}, Ticks -> {rotatedLabels, Automatic},
PlotRange -> {{0, 5}, Automatic}] • I think they wanted the numbers in the ticks, as well as labels below the numbers. Feb 23, 2017 at 21:38
• @Nasser I didn't gather that originally as it wasn't made explicitly clear, but I've edited my response to hopefully accommodate the OP in case that's what they're after. Thanks!
– ktm
Feb 23, 2017 at 21:45
• Thank you very much. The MapThread suggestion works well, and I've been able to easily modify the idea for application barplots and matrix plots. Feb 24, 2017 at 20:32