MATLAB: How to display characters vertically in tick label for bar plot

labelsplotnewlineMATLABtick

I am using MATLAB R2017b to create a bar plot. I have 2 x-tick labels on a bar plot, 'test1' and 'test2', I want to align them vertically, that is each character in a new line. For example, like this:

I tried using the following code:
t1 = "t" + newline + "e" + newline + "s" + newline + "t" + newline + "1";
t2 = "t" + newline + "e" + newline + "s" + newline + "t" + newline + "2";
bar([t1 t2],[2 3])
But I got an error, how to resolve this?

Best Answer

Tick labels on the Axes does not support multi-line labels without using TeX interpreter characters.
The "\newline" TeX command can be used to create a newline as in this example:
b = bar([2 3]);
xticks([1 2]);
lbls = ["t\newlinee\newlines\newlinet\newline1" "t\newlinee\newlines\newlinet\newline2"];
xticklabels(lbls);