Help With Graphing on the Same Plot
2 ビュー (過去 30 日間)
古いコメントを表示
Hello! I am hoping someone can help me find a way to have these graphs lined up so the x-axis with months on them line up. ( 200 months in the scallops line up with 200 months in the ray population and such). I think the name for it is a stacked time series.
Here's my code! Thank you very much in advance.
% Trohpic Cascade to calculate the changes in population in scallops and
% cownose rays based on interactions with each other
clear
% Inputs
R(1) = 100; % Initial poplation of cownose rays
B(1) = 10000; % Initial population of scallops
dR = .02; % Death rate of rays in abscence of scallops
gamma = 0.05; % Growth rate of scallops in absence of cownose rays
T = 1000; % Time in months that the simulation will be run for
Rcrit = 83; % Critical value of rays to support a stable scallop population
Bcrit = 6000; % Critical value of scallops needed to support a stable cownose ray population
for t = 1 : T-1
B(t+1) = B(t) + computeDeltaB(gamma, R(t), Rcrit, B(t));
R(t+1) = R(t) + computeDeltaR(dR, B(t), Bcrit, R(t));
end
figure;
plot(B);
hold on
xlabel('time (months)', 'FontSize' ,18);
ylabel ('B (Scallops)', 'FontSize', 18);
title('Scallops Over Time', 'FontSize', 18)
figure;
plot(R);
xlabel('time (months)', 'FontSize', 18);
ylabel ('R (Rays)', 'FontSize', 18);
title(' Rays over Time', 'FontSize', 18)
hold off
0 件のコメント
採用された回答
Star Strider
2020 年 10 月 9 日
Plotting specific time vectors as well as ‘R’ or ‘B’ might do what you want. (We cannot run your code.)
Example —
plot(tR, R)
and
plot(tB, B)
Second option — plot them both on the same axes:
figure
plot(tR, R)
hold on
plot(tB,B)
hold off
xlabel('time (months)', 'FontSize' ,18);
ylabel('Population')
legend('Rays', 'Scallops', 'Location','best')
.
4 件のコメント
その他の回答 (2 件)
Asad (Mehrzad) Khoddam
2020 年 10 月 9 日
The second figure command, creates a new figure,
you can comment it out:
% The second graph
%figure;
plot(R);
xlabel('time (months)', 'FontSize', 18);
ylabel ('R (Rays)', 'FontSize', 18);
title(' Rays over Time', 'FontSize', 18)
hold off
Asad (Mehrzad) Khoddam
2020 年 10 月 10 日
% Trohpic Cascade to calculate the changes in population in scallops and
% cownose rays based on interactions with each other
clear
% Inputs
R(1) = 100; % Initial poplation of cownose rays
B(1) = 10000; % Initial population of scallops
dR = .02; % Death rate of rays in abscence of scallops
gamma = 0.05; % Growth rate of scallops in absence of cownose rays
T = 1000; % Time in months that the simulation will be run for
Rcrit = 83; % Critical value of rays to support a stable scallop population
Bcrit = 6000; % Critical value of scallops needed to support a stable cownose ray population
for t = 1 : T-1
B(t+1) = B(t) + computeDeltaB(gamma, R(t), Rcrit, B(t));
R(t+1) = R(t) + computeDeltaR(dR, B(t), Bcrit, R(t));
end
yyaxis left;
plot(t,B);
ylabel ('B (Scallops)', 'FontSize', 18);
title('Scallops Over Time', 'FontSize', 18);
yyaxis right
plot(t,R);
xlabel('time (months)', 'FontSize', 18);
ylabel ('R (Rays)', 'FontSize', 18);
title(' Rays over Time', 'FontSize', 18)
xlabel('time (months)', 'FontSize' ,18);
hold off
2 件のコメント
Asad (Mehrzad) Khoddam
2020 年 10 月 10 日
If you want to have two different plots, use subplot:
% Trohpic Cascade to calculate the changes in population in scallops and
% cownose rays based on interactions with each other
clear
% Inputs
R(1) = 100; % Initial poplation of cownose rays
B(1) = 10000; % Initial population of scallops
dR = .02; % Death rate of rays in abscence of scallops
gamma = 0.05; % Growth rate of scallops in absence of cownose rays
T = 1000; % Time in months that the simulation will be run for
Rcrit = 83; % Critical value of rays to support a stable scallop population
Bcrit = 6000; % Critical value of scallops needed to support a stable cownose ray population
for t = 1 : T-1
B(t+1) = B(t) + computeDeltaB(gamma, R(t), Rcrit, B(t));
R(t+1) = R(t) + computeDeltaR(dR, B(t), Bcrit, R(t));
end
subplot(2,1,1)
plot(t,B);
xlabel('time (months)', 'FontSize', 18);
ylabel ('B (Scallops)', 'FontSize', 18);
title('Scallops Over Time', 'FontSize', 18);
subplot(2,1,2)
plot(t,R);
xlabel('time (months)', 'FontSize', 18);
ylabel ('R (Rays)', 'FontSize', 18);
title(' Rays over Time', 'FontSize', 18)
xlabel('time (months)', 'FontSize' ,18);
hold off
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!