How is it possible to rotate the xticklabels in Octave?

I have implemented xticklabels in my code but now I need to rotate them not to have any label confliction.
How can this be done ?

Thank you.

It is not possible out of the box. Your best bet is to either remove manually some tick labels (see xticks and xticklabels functions) or simulate the tick labels using text objects. Here is an example that you could adapt to your needs:

## First demo for "datetick
clf;
yr = 1900:10:2000;
pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ...
       203.984, 227.225, 249.623, 282.224];
plot (datenum (yr, 1, 1), pop);
ylabel ("US population (millions)");
datetick ("x", "YYYY");

## Now retreive ticklabels, simulate them and remove the original ones
xtl = xticklabels ();
xt = xticks ();
for ii = 1:numel (xtl)
  text (xt(ii), 49, xtl{ii}, "rotation", 90, "horizontalalignment", "right")
endfor
xticklabels ([]);

image

1 Like

Agree that the easiest solution is to plot every OTHER xtick. See the xticks function or use the property "xtick" of the current axes object (gca).

For the future, there is an xticklabelrotation property of the axes object that will rotate the labels by the specified amount. However, this has not yet been implemented (maybe it will be for version 7.0).

1 Like

Unfortunately, I did not manage yet. I have two arrays of type double (time and height) and another one of type cell (time_labels) (all with the same dimensions).

image

Your code is putting all labels at the same place. The original code that Pantxo posted uses the same Y-value (49, although that will need to change to whatever value your x-axis has been placed at), and then varies the x location with xt(ii).

text (xt(ii), 49, xtl{ii}, "rotation", 90, "horizontalalignment", "right")
1 Like

Thank you. Through your reply I understood my mistake,

Sorry for asking once again, but I am preparing a presentation with all the plots obtained, and wish to have good visuals. Is there any possibility of rotating the labels by 45 degrees instead of 90 degrees?
I tried replacing the value of 90 to 45 in the text function but it did not work.

Thank you

Not on screen (a known limitation/problem), but they will be in png/pdf printout.

Dmitri.