2 Line Styles for A Single Plot- How to Change Plotting Styles

I've attached a picture of a plot and circled where I would like to change the solid line I circled to a different style (like a dashed line). How do I do that?
B = 0.75; C = 0.8; p =0.5;
A = linspace((1-p)*B*(1-C),1.5);
figure (2)
[l1,~]= bifurcation_lysogen_pops(A);
[~,l2]= bifurcation_lysogen_pops(A);
plot(A,l1, A, l2)
yline(0); %E_H and E_0 l
ylim([-0.2 1])
xlim([0 1])
function [l1,l2] = bifurcation_lysogen_pops(A)
B = 0.75; C = 0.8; p =0.5;
v= B*(1-C);
l1 = (C*p*v)./(A-(1-p)*v); %E* lysogen population
l2 = (B-A)./B; %E_VL lysogen population
end
l2 is the red plot and l1 is the blue plot

 采纳的回答

Here's one possibility
B = 0.75; C = 0.8; p =0.5;
A = linspace((1-p)*B*(1-C),1.5);
figure (2)
[l1,l2]= bifurcation_lysogen_pops(A);
l1(1)=[]; l2(1)=[]; A(1)= []; % get rid of infinity in l1;
hiindx = find(l1>l2 & A<0.5);
Ahi = A(hiindx);
l1hi = l1(hiindx);
Alo = A(max(hiindx):end);
l1lo = l1(max(hiindx):end);
plot(Ahi,l1hi,'b--',Alo,l1lo,'b',A,l2)
yline(0); %E_H and E_0 l
ylim([-0.2 2])
xlim([0 1])
function [l1,l2] = bifurcation_lysogen_pops(A)
B = 0.75; C = 0.8; p =0.5;
v= B*(1-C);
l1 = (C*p*v)./(A-(1-p)*v); %E* lysogen population
l2 = (B-A)./B; %E_VL lysogen population
end

5 个评论

Thanks! I would also like to change the part I circled in this screenshot to a solid red line. Also, do you mind explaining your code to me, so I can do it on my own for different plots in the future?
Modify the previous code as follows
B = 0.75; C = 0.8; p =0.5;
A = linspace((1-p)*B*(1-C),1.5);
figure (2)
[l1,l2]= bifurcation_lysogen_pops(A);
l1(1)=[]; l2(1)=[]; A(1)= []; % get rid of infinity in l1;
hiindx = find(l1>l2 & A<0.5);
Ahi = A(hiindx);
l1hi = l1(hiindx);
Alo = A(max(hiindx):end);
l1lo = l1(max(hiindx):end);
l2hi = l2(hiindx);
l2lo = l2(max(hiindx):end);
plot(Ahi,l1hi,'b--',Alo,l1lo,'r',Ahi,l2hi,'r',Alo,l2lo,'b--')
yline(0); %E_H and E_0 l
ylim([-0.2 2])
xlim([0 1])
function [l1,l2] = bifurcation_lysogen_pops(A)
B = 0.75; C = 0.8; p =0.5;
v= B*(1-C);
l1 = (C*p*v)./(A-(1-p)*v); %E* lysogen population
l2 = (B-A)./B; %E_VL lysogen population
end
hiindx = find(l1>l2 & A<0.5); % This line finds where the data points are that satisfy
% the conditions that the values of l1 are greater than
% those of l2, AND where the values of A are less than 1/2.
Ahi = A(hiindx); % This line selects all the points of A that are pointed to
% by hiindx
l1hi = l1(hiindx); % This line selects all the points of l1 that are pointed to
% by hiindx
Alo = A(max(hiindx):end); % This line selects all the remaining points of A
l1lo = l1(max(hiindx):end); % This line selects all the remaining points of l1
% etc.
plot(Ahi,l1hi,'b--',Alo,l1lo,'r',Ahi,l2hi,'r',Alo,l2lo,'b--') % This line just plots the
% various line sections
% assigning them the
% desired colours.
Thank you! Also, what do you mean by "pointed to by," and is "max" used?
The vector l1, say, has values listed in order: l1(1), l1(2), l1(3), ...etc. The "find" command finds the numbers 1, 2, 3, etc that correspond to the specified conditions. So, for example, if the values l1(1) and l1(2) were larger than l2(1) and l2(2) and all the other values of l1 were smaller than the other values of l2, then hiindx would be a vector consisting of the numbers 1 and 2 (i.e. hiindx would be [1, 2]). That is hiindx would "point to" the first two vaues of a vector. l1(hiindx) would "point to" l1(1) and l1(2). A(hiindx) would "point to" A(1) and A(2).
Since the values of hiindx increase in value. the last one will be the largest, so max(hiindx) will pick out the last value. One could also use hiindx(end), for example, to do the same thing.
Hope this helps.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Log Plots 的更多信息

产品

版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by