Legend incorrect when plotting with quiver
    11 views (last 30 days)
  
       Show older comments
    
    Dayne Filer
 on 12 Sep 2017
  
    
    
    
    
    Answered: Reece Teramoto
    
 on 15 Sep 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.
0 Comments
Accepted Answer
  Reece Teramoto
    
 on 15 Sep 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.
0 Comments
More Answers (0)
See Also
Categories
				Find more on Vector Fields in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
