Context: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
load('topo.mat', 'topo');
hT = title('Demonstration of Demonstration of Missing Title', 'FontSize', 16);
hT.Position(2) = hT.Position(2) + 0.02;
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
print('missingTitle_print.pdf', '-dpdf')
saveas(hA, 'missingTitle_saveas.pdf')
exportgraphics(hA, 'missingTitle_exportgraphics.pdf')