Plot title disappears if ymax < 1

My plot titles are disappearing if ymax is less than 1, presumably because the " X 10^-2" bit ends up in the area where the title goes. It is not affected by the length (number of characters) of the plot title. I have only noticed this since I started shrinking my plots vertically from the default size so that three of them will fit on one page in a word document file.
The code for shrinking vertically:
currentSize = get(gcf, 'Position');
set(gcf, 'Position', [currentSize(1) currentSize(2) currentSize(3) 280])
My current workaround is to increase the plot window size, add the title, then reduce the plot size back:
figurePosition = get (gcf, 'Position');
set (gcf, 'Units', 'normalized', 'Position', [0,0,1,1]);
% add plot titles etc here
set (gcf, 'Units', 'pixels', 'Position', figurePosition);
This works for long plot titles, even if the text overlaps the " X 10^-2" bit.
I am using R2008b.

回答(1 个)

If you set the axis ylabel property explicitly, then the power of 10 will not be printed.
curytick = get(gca, 'YTick');
set(gca, 'YLabel', cellstr(num2str(curytick(:))))
The (:) is important: the ticks are usually a row vector and they need to be a column vector for num2str() to produce the correct output format.

2 个评论

If I change 'YLabel' to 'yticklabel', this works to get rid of overlapping text due to the exponent. I still need to change the figure size when adding the plot title or the title disappears. So my theory on why this is happening is wrong.
In the opening post I should have said the title disappears for ymax < 0.01 - this is still the case.
That's a handy trick for forcing a column vector...
Yes, sorry, should have been YTickLabel

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by