title shifted into figure box
7 次查看(过去 30 天)
显示 更早的评论
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
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').
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!