필터 지우기
필터 지우기

fitted line in a scatter plot within a subplot

조회 수: 3 (최근 30일)
msh
msh 2015년 4월 20일
편집: Cindy Solomon 2015년 4월 21일
Hi,
I would like to put a fitted line in a scatter plot, that I include in a figure with multiple plots. I am attaching the figure I produce, and I circle the subplot that I am referring to. Below you can find the code for my plotting.
figure
subplot(3,2,1) % first subplot
plot(thetaplot)
title('Human Capital Share')
xlabel('Time')
ylabel('Theta')
subplot(3,2,2) % first subplot
plot(khplot)
title('K/H ratio')
xlabel('Time')
ylabel('K/H')
subplot(3,2,3) % first subplot
plot(phiplot)
title('Sector II Share')
xlabel('Time')
ylabel('Phi')
subplot(3,2,4) % first subplot
plot(zhplot)
title('Z/H ratio')
xlabel('Time')
ylabel('Z/H')
subplot(3,2,5) % first subplot
plot(uplot)
title('MPC')
xlabel('Time')
ylabel(' Consumption per Wealth ')
subplot(3,2,6) % first subplot
plot(kh(500:T), kh(501:T+1), 'k.')
title('Policy Function for K/H')
xlabel('K_t')
ylabel('K_{t+1}')

채택된 답변

Cindy Solomon
Cindy Solomon 2015년 4월 21일
편집: Cindy Solomon 2015년 4월 21일
To add a fitted line to a specific subplot, you can just use the "Basic Fitting Tool" in MATLAB. This can be accessed by going to the "Basic Fitting" option in the "Tools" menu on your figure. Equivalently, you can also plot the line directly on your specific subplot programmatically. For example, if your data was x and y:
p = polyfit(x,y,1)
% polyfit(x,y,n) finds the coefficients of a polynomial p(x) of degree n
% that fits the data. This example demonstrates linear trend.
yLin = polyval(p,x);
% polyval(p,x) returns the value of a polynomial of degree n evaluated at
% x.
subplot(3,2,6)
plot(x,y)
hold on
plot(x,yLin,'r');
Hope this helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by