4
$\begingroup$

I have a list of data where each point should have a label. I would like the labels to be below the plot, where tick labels usually are. This is what I have so far:

data = {1, 4, 3, 6};
labels = {"long name", "short", "what is this even", "this thing"};

ListPlot[data, 
 Ticks -> {MapIndexed[{First[#2], Rotate[#1, 90 Degree]} &, labels], Automatic}]

image of generated ListPlot

The problem is that the rotated labels are centered. How can I right-align the labels so that the space between the axis and the label is the same for each label?

$\endgroup$
5
$\begingroup$

Use

Rotate[#1, 90 Degree, {Right, Center}]

instead. This moves the point of rotation to the right and vertical centre of the bounding box of each string.

What I suspect is that Mathematica aligns the bounding boxes by aligning their origins. By moving the rotation point, the origin is moved to that point perhaps, and now the boxes are right-aligned.

$\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.