Legend incorrect when plotting with quiver

1 visualización (últimos 30 días)
Dayne Filer
Dayne Filer el 12 de Sept. de 2017
Respondida: Reece Teramoto el 15 de Sept. de 2017
I cannot get the legend to display as desired when plotting with quiver. I am using R2017a.
% Some parameters
k1 = 1;
k2 = 1;
k3 = 10;
E = 10;
% establish the grid of possible C and S values
[cmesh,smesh] = meshgrid(0:0.5:10,0:0.5:10);
% Calculate nullcine and the tendencies at each value of the grid
cnull = k1.*E.*smesh./(k1.*smesh + k2 + k3);
dsdt = -k1.*(E - cmesh).*smesh + k2.*cmesh;
dcdt = k1.*(E - cmesh).*smesh - (k2 + k3).*cmesh;
% Plot the phase plane
quiver(smesh,cmesh,dsdt,dcdt);
hold on;
plot(smesh, cnull);
hold on;
plot([1:10],[1:10]);
legend('Trajectory', 'C nullcline', 'S(t),C(t)');
xlabel('S');
ylabel('C');
axis([0,10,0,10]);
title('Phase Plane');
The line colors do not match the plotted lines in the figure created.

Respuesta aceptada

Reece Teramoto
Reece Teramoto el 15 de Sept. de 2017
Change this line:
plot(smesh, cnull);
to this:
plot(smesh(:,1), cnull(:,1));
Originally, since 'smesh' and 'cnull' are both 2-D matrices where each column is identical, you were plotting the same curve many times on top of each other with this one line of code, since you were using the 'plot' function with two matrices as inputs.
This caused many curves to be plotted on the figure, and the 'legend' command will pull the plots in chronological order unless otherwise specified.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by