title shifted into figure box
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 13 Jul. 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').
Akzeptierte Antwort
Jan
am 13 Jul. 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 Kommentare
Jan
am 13 Jul. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!