title shifted into figure box

7 次查看(过去 30 天)
Dan
Dan 2011-7-13
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 个评论
Jan
Jan 2011-7-13
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 2011-7-13
Walter, I'm using 7.10.0(R2010a) and my operating system is Windows XP

请先登录,再进行评论。

采纳的回答

Jan
Jan 2011-7-13
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 个评论
Dan
Dan 2011-7-13
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 2011-7-13
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by