Subplot Title Positioning fail/succeed depending on data

I have two sets of data (after processing the e in the code in 2 ways). When I do the same thing with each of them, one of them produces what I want and one of them doesn't. I am perplexed exactly what the issue could be. The only thing different is the data between them. But the subplot b and c titles completely screw up and end up inside the previous plots somehow, as you can see from the 2 files with self-explanatory names that are produced from the code.
%%Working
clear;clc;
yshift=0.1;
y_hat=[76 66 73.5 73.5 93.25 83.25 90.75 90.75]';
y_bar =[87.5 65 71 85.5 80 86 90 92]';
e=y_bar-y_hat;
SSE=sum(e.^2);
MSE=SSE/12;
d=e/sqrt(MSE);
close all
figure;
subplot(3,1,1), hold on, box on, hist(e),h = findobj(gca,'Type','Patch');
ylim([0 2.2]), set(h,'FaceColor',[1 1 1], 'EdgeColor','black','LineWidth',1), xlabel('Residual'), ylabel('Frequency'),ht=title('a: Histogram of Residuals');
P = get(ht,'Position');set(ht,'Position',[P(1) P(2)+yshift]);
subplot(3,1,2), hold on, box on, plot(d,'ok','MarkerSize',8,'LineWidth',1.25),
plot([0 9],[0 0],'--k'),xlabel('Sample Number'),ylabel('Standardized Residual'), ht=title('b: Standardized Residuals vs Samples');
P = get(ht,'Position');set(ht,'Position',[P(1) P(2)+yshift]);
subplot(3,1,3), hold on, box on, plot(y_hat,d,'ok','MarkerSize',8,'LineWidth',1.25),
plot([65 95],[0 0],'--k'),ylabel('Standardized Residual'),xlabel('Predicted Y'),ht=title('c: Standardized Residuals vs Predicted Response');
P = get(ht,'Position');set(ht,'Position',[P(1) P(2)+yshift]);
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure 2: Residual Analysis for Question 2','HorizontalAlignment','center','VerticalAlignment', 'top','FontSize',20)
print('Working','-dpdf','-fillpage')
close all
%%Not Working
d=e/sqrt(28.1667);
figure;
subplot(3,1,1), hold on, box on, hist(e),h = findobj(gca,'Type','Patch');
ylim([0 2.2]), set(h,'FaceColor',[1 1 1], 'EdgeColor','black','LineWidth',1), xlabel('Residual'), ylabel('Frequency'),ht=title('a: Histogram of Residuals');
P = get(ht,'Position');set(ht,'Position',[P(1) P(2)+yshift]);
subplot(3,1,2), hold on, box on, plot(d,'ok','MarkerSize',8,'LineWidth',1.25),
plot([0 9],[0 0],'--k'),xlabel('Sample Number'),ylabel('Standardized Residual'), ht=title('b: Standardized Residuals vs Samples');
P = get(ht,'Position');set(ht,'Position',[P(1) P(2)+yshift]);
subplot(3,1,3), hold on, box on, plot(y_hat,d,'ok','MarkerSize',8,'LineWidth',1.25),
plot([65 95],[0 0],'--k'),ylabel('Standardized Residual'),xlabel('Predicted Y'),ht=title('c: Standardized Residuals vs Predicted Response');
P = get(ht,'Position');set(ht,'Position',[P(1) P(2)+yshift]);
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 1,'\bf Figure 2: Residual Analysis for Question 2','HorizontalAlignment','center','VerticalAlignment', 'top','FontSize',20)
print('Not Working','-dpdf','-fillpage')
close all

 채택된 답변

KSSV
KSSV 2017년 3월 24일
Instead of simply figure in line number 11, use
figure('units','normalized','outerposition',[0 0 1 1])

댓글 수: 3

Thanks. What's the 0 0 1 1? Is it the part which fixes the problem?
No.....it makes the figure larger of size of your computer screen..
How did you know that would fix the problem tho?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

제품

질문:

2017년 3월 24일

댓글:

2017년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by