フィルターのクリア

Subplot Title Positioning fail/succeed depending on data

1 回表示 (過去 30 日間)
bloodtalon
bloodtalon 2017 年 3 月 24 日
コメント済み: bloodtalon 2017 年 3 月 24 日
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 件のコメント
KSSV
KSSV 2017 年 3 月 24 日
No.....it makes the figure larger of size of your computer screen..
bloodtalon
bloodtalon 2017 年 3 月 24 日
How did you know that would fix the problem tho?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by