How do I make two line plots the same colour?
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Georgia Willmot
le 19 Oct 2021
Réponse apportée : Georgia Willmot
le 19 Oct 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 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!