Legend incorrect when plotting with quiver

3 次查看(过去 30 天)
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.

采纳的回答

Reece Teramoto
Reece Teramoto 2017-9-15
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by