Reputation: 939
A book I'm reading contains the following diagram.
I'm looking to replicate as closely as possible the following diagram in MATLAB. I managed to recreate the lines, but am having trouble filling the colours in.
possible_colours = {'r','g','b','c','m','y','w','k','r'};
H = [0.01:0.01:0.99];
colour_counter = 0;
for ii = -0.8:0.2:0.8
colour_counter = colour_counter + 1;
colour_now = possible_colours{colour_counter};
ORSS = ones(1,size(H,2))*ii;
F = (H .* (1-ORSS)) ./ ((1-2.*H) .* ORSS + 1);
hold on
plot(F,H)
fill(F,H,colour_now);
end
With fill(F,H,colour_now)
taken out the code perfectly recreates the required lines. However, the fill isn't correct.
This heavily upvoted answer by @Doresoom seems relevant, but it's a bit different because in that example the x-values are held constant, while in my case it's the y-values that are held constant. Also, in that case there is only a pair lines, whereas I have lots of them.
Upvotes: 0
Views: 192
Reputation: 2351
I think this is a solution:
%possible_colours = {'r','g','b','c','m','y','w','k','r'};
possible_colours = {'r','g','b','c','r','k','w','y','m'};
H = [0.01:0.01:0.99];
figure; hold on
fill([0 1 1],[0 0 1],colorlowerhalf)
fill([0 1 0],[0 1 1],colorupperhalf)
colour_counter = 0;
for ii = -0.8:0.2:0
colour_counter = colour_counter + 1;
colour_now = possible_colours{colour_counter};
ORSS = ones(1,size(H,2))*ii;
F = (H .* (1-ORSS)) ./ ((1-2.*H) .* ORSS + 1);
hold on
plot(F,H)
fill(F,H,colour_now);
end
for ii = 0.8:-0.2:0
colour_counter = colour_counter + 1;
colour_now = possible_colours{colour_counter};
ORSS = ones(1,size(H,2))*ii;
F = (H .* (1-ORSS)) ./ ((1-2.*H) .* ORSS + 1);
hold on
plot(F,H)
fill(F,H,colour_now);
end
It permits to avoid the overlap of the filled areas.
But there still is some problem with the definition of the areas to fill.
For that you need to redefine H
:
H = [0:0.01:1];
Upvotes: 2