How can I add a space below the title?

Hi, I have the next code.
figure(1), clf;
% Plotting T C
subplot(3,1,1)
pcolor(gridx/1000,gridy/1000,tk1-273);
shading interp;
axis tight;
colormap(jet);
title(['T (^oC),' ' Time = ',num2str(timesum*1e-6/(365.25*24*3600)), ' (Myr)'])
colorbar;
axis ij image;
I am getting the image, but I have a problem. The title is overlapping the figure, so I want to add some space between the title and the figure but I do not know how to do that.
Thank you very much.

Answers (2)

If you need to add space below your title, you can add newline, something like this:
title(['T (^oC),' ' Time = ',num2str(timesum*1e-6/(365.25*24*3600)), ' (Myr)', newline])
newline is more convenient to use comparing with sprintf('\n') for example .

2 Comments

Hi.
Thank you very much. It worked perfect. But I have an additional question. Is it possible to edit the size of the space?
In order to change the position of the title, you can use the Position property of the title .
Please have a look at this thread:
https://www.mathworks.com/matlabcentral/answers/408173-title-position-below-the-x-axis.

Sign in to comment.

I actually find sprintf() much easier to read than having a bunch of extra apostrophes, commas, and function calls to num2str():
caption = sprintf('T (^oC), Time = %f (Myr)\n', timesum*1e-6/(365.25*24*3600))
t = title(caption);
You can add addition \n if you want to add additional space that is a whole line space. Use the Position property of the title handle:
caption = sprintf('T (^oC), Time = %f (Myr)\n', timesum*1e-6/(365.25*24*3600))
titleHandle = title(caption)
% Place title at the left side of the plot by using the Position property:
ax = gca; % ax.Position is [xLeft, yTop, width, height] of the axes.
titleHandle.Position = [ax.Position(1), titleHandle.Position(2:end)];

Asked:

on 15 Nov 2022

Answered:

on 15 Nov 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!