필터 지우기
필터 지우기

Legend incorrect when plotting with quiver

조회 수: 3 (최근 30일)
Dayne Filer
Dayne Filer 2017년 9월 12일
답변: Reece Teramoto 2017년 9월 15일
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