How do I make two line plots the same colour?

25 Ansichten (letzte 30 Tage)
Georgia Willmot
Georgia Willmot am 19 Okt. 2021
Beantwortet: Georgia Willmot am 19 Okt. 2021
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 Kommentare
KSSV
KSSV am 19 Okt. 2021
Show us your code. Let us help you.
Georgia Willmot
Georgia Willmot am 19 Okt. 2021
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).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Georgia Willmot
Georgia Willmot am 19 Okt. 2021
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')

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by