How do I make two line plots the same colour?

25 ビュー (過去 30 日間)
Georgia Willmot
Georgia Willmot 2021 年 10 月 19 日
回答済み: Georgia Willmot 2021 年 10 月 19 日
I've used an Events solver to solve a system of two ODEs for x and y, where the system solves ODESET1 up to a given x value (this is what the Events solver checks for) and then solves ODESET2 after x has reached this value.
This is all fine, and I've now essentially got four time series solutions: x for first set, y for first set, then x for second set, y for second set (these do match up in the middle).
What I want to do is plot these four solutions on one graph. I can do this, however Matlab makes all four plots different colours because it sees them as four separate time series plots. What I'd ideally like is to have each solution pair (x for ODESET 1, x for ODESET2) and (y for ODESET1, y for ODESET2) the same colour, so I just get one trajectory in one colour for x and one for y in another, over the full time series.
I have tried plotting them all separately using plot() four times, however it doesn't like this...
Hope this makes sense! The chunk of my code in question:
...
options = odeset('Events', @Diffu ); % Stop integration of ODESET1 when condition reached
[t,xa] = ode45(f,tspan, [x0 y0], options) ; % Solve system with Events Function
tspan2 = [t(end) tspan(2)] ; % Solve ODESET2 for remaining timespan
y1 = [Xstar xa(:,end)];
[t,y] = ode15s(@(t,y) odefcn2(t,y,a,b), tspan2, y1);
%plots
figure(1)
plot(t,xa(:,1), t, (xa(:,2)))
hold on
xlabel('Time (Days)');
xlim(tspan);
plot(t,y(:,1),t,(y(:,2)))
lgd.FontSize = 16;
xlabel('Time (Days)');
  4 件のコメント
KSSV
KSSV 2021 年 10 月 19 日
Show us your code. Let us help you.
Georgia Willmot
Georgia Willmot 2021 年 10 月 19 日
Sorry, I've put this up now. So it runs fine, it's just that I essentially want the two lines for xa(:,1) and y(:,1) to be the same colour, and the same for xa(:,2) and y(:,2).

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

採用された回答

Georgia Willmot
Georgia Willmot 2021 年 10 月 19 日
Ah! I have realised I can set them all individually. For anyone with the same question, you can just do this:
plot(t,xa(:,1), 'b', t, (xa(:,2)), 'r')
plot(t,y(:,1), 'b', t,(y(:,2)), 'r')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by