How to adjust the position of a title in a subplot
조회 수: 60 (최근 30일)
이전 댓글 표시
So I have the following subplot:

With the following code:
figure
subplot(1,2,1)
imagesc(im);
axis equal;
axis off;
hold on;
plot(position(:,1),position(:,2),'o','MarkerEdgeColor','r','LineWidth',1.5,'MarkerSize',10);
title('Detected Particles', 'FontSize',14);
histpos = [0.5703,0.2707,0.3347,0.4897];
subplot('position',histpos)
hist(FWHM, 6)
colormap default
xlabel('FWHM', 'FontSize',16)
ylabel('Frequency', 'FontSize',16)
set(gca,'FontSize',14);
title('Histogram of FWHM Values', 'FontSize',16);
As you can see, the title for the first subplot is in an odd position and I can't figure out why. It doesn't do that when I have it as a regular figure and not a subplot.
Any suggestions for how to fix it?
Thanks
댓글 수: 0
채택된 답변
dpb
2020년 7월 16일
It's the axis equal that does it -- take out the axis off afterwards and you'll see the position of the title isn't all that funny after all.
The side-by-side subplot is squished horizontally; when you make axis equal that shrinks the image in the y direction but doesn't change the overall axis size.
To fix, make the following changes--
...
xlm=xlim; % retrieve x axis limits
title('Detected Particles','Position',[mean(xlm) xlm(1)],'FontSize',14); % use for title positioning
The axis equal leaves y axis scaled to make the same range as x-axis in center so postioning the title at center and start of x axis moves it to the top edge of the scale image. It's the left edge instead of right since images have origin at upper left instead of LL as a regular plot.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!