3
$\begingroup$

Is it possible to have 3 x axes labels like in the image below? I would like to have letters exactly under corresponding ticks. I am considering overlaying three plots with separate x axis together with Show but this does not seem like a clean solution.

enter image description here

$\endgroup$
2
  • $\begingroup$ show us your problem and code please $\endgroup$
    – Alrubaie
    Oct 11, 2019 at 13:02
  • $\begingroup$ You can use Ticks or FrameTicks (please look up Ticks in the docs), and use a Column expression for each tick label. You should be able to handle it from here—let us know if there's anything that's unclear. $\endgroup$
    – Szabolcs
    Oct 11, 2019 at 13:36

2 Answers 2

4
$\begingroup$
SeedRandom[1]
data = Transpose[{RandomSample[Range[50], 20], RandomInteger[100, 20]}];

labels = Column[#, Spacings -> .5, Alignment -> Center] & /@ 
  Join[List /@ data[[All, 1]], RandomChoice[CharacterRange["A", "Z"], {20, 3}], 2];

epilog = MapThread[Inset[#2, {#[[1]], 0}, {0, 1.2}] &, {data, labels}];

legend = labels /. {(Spacings -> _) -> Spacer[1], Column->Row};

ListPlot[List /@ data, 
 Epilog -> epilog,
 PlotLegends -> legend,
 PlotRange -> {0, 100}, PlotRangeClipping -> False, 
 ImagePadding -> {{Automatic, Automatic}, {Scaled[.2], Automatic}},
 Ticks -> {data[[All, 1]], Automatic},
 TicksStyle -> {FontOpacity -> 0, Automatic}]

enter image description here

$\endgroup$
2
$\begingroup$

You can place a newline ("\n") to create rows in a text string such as "1\nA\n-". To automate this a bit to mimic your graph:

row1 = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
row2 = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
row3 = {"-", "-", "H", "H", "H", "H", "-", "-", "-", "-"};
ticks = Table[Style[tick1[[i]] <> "\n" <> tick2[[i]] <> "\n" <> tick3[[i]], Bold, 18], {i, 10}];
ticks = Transpose[{Range[10], ticks}];

data = Range[10];
ListPlot[data, Frame -> True, 
 FrameTicks -> {{Automatic, None}, {ticks, None}},
 PlotRangePadding -> {{Automatic, Automatic}, {1, 0.5}}]

3 rows of tick labels

The PlotRangePadding option is needed to provide the extra space for the 3 rows of tick labels.

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