title shifted into figure box

7 visualizaciones (últimos 30 días)
Dan
Dan el 13 de Jul. de 2011
Hello,
I am running a for loop to produce several figures at once in some of the figures the title gets shifted into the figure box and is obstructed by some of my bars.
Here is the code I am using:
for i = 1:6
X(1) = ave_dur_spei(1,i);
X(2:7) = ave_dur_spei_gcm_ann(1:6,i);
bar_h=bar(X);
bar_child=get(bar_h,'Children');
set(bar_child,'CData',X);
set(gca,'XTickLabel',{'Historical';'cnrm-cm3';'gfdl-cm2-1';'miroc3-2-med';'mpi-echam5';'ncar-ccsm3';'ncar-pcm1'},'fontsize',18)
xticklabel_rotate
ylabel('average duration (months)','fontsize',18)
title([num2str(x(i)),'-month SPEI: Austin, NV (duration below 90th percentile)'],'fontsize',14)
set(gca,'fontsize',18)
refline(0,X(1))
saveas(gcf,['austin_',num2str(x(i))],'png')
close gcf
end
The error only occurs when i = 3, 4, and 5...
Can anyone help me?
Thanks, Dan
  3 comentarios
Jan
Jan el 13 de Jul. de 2011
How strange that "close gcf" works, because this means "close('gcf')", but Matlab understands what the user wants - a first version of feature('dwim').
Dan
Dan el 13 de Jul. de 2011
Walter, I'm using 7.10.0(R2010a) and my operating system is Windows XP

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 13 de Jul. de 2011
TITLE creates a TEXT object with 'data' units. The position of the title is influenced by the axes' fontsize. Solution: Set the axes' fontsize at first and use 'normlized' units:
set(gca, 'fontsize', 18);
title([num2str(x(i)), '-month etc.'], 'fontsize', 14, ...
'units', 'normalized', 'Position', [0.5, 1.02])
  2 comentarios
Dan
Dan el 13 de Jul. de 2011
Thanks again Jan! I'm assuming if I'm having the same type of problem with the ylabel I can use a similar fix?
Jan
Jan el 13 de Jul. de 2011
The YLabel considers the width of the YTickLabels, which is not easy to control. But it works equivalent to the title.
You can look in the source of ylabel.m.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by