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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by