MATLAB: How to change XTick Labels in a heatmap

heatmapundocumentedxticks

Hello I am trying to Change the X ticklabels of a heatmap plot. Apparently, the normal procedure over "xticklabels" is not supported for heatmaps. So I tried out a Workaround, which still has a bug. This is the example:
figure;
heatmap(my_matrix, 'Colormap', colorMap, 'ColorbarVisible', 'on', 'XLabel', 'Time', 'YLabel', 'September')
ax = gca;
axp = struct(ax);
axp.Axes.XTickLabel = num2cell(0:23)
This works in the first go, however if I then change the size of my figure (i.e. I expand to full screen), the X ticklabels return back to their original values (which is 1:24). I have also tried to adapt axp.XAxis.TickLabels, which has the same result. Could you give me a hint on what to do?

Best Answer

The tick labels are deceptively called *data.
figure;
my_matrix = rand(3);
heatmap(my_matrix, 'Colormap', parula(3), 'ColorbarVisible', 'on', 'XLabel', 'Time', 'YLabel', 'September')
ax = gca;
ax.XData = ["Hello" "World" "Thursday"]
Or simply
heatmap(etc..., 'XData', ["Hello" "World" "Thursday"])