Creating different sections in one graph

10 次查看(过去 30 天)
Hi,
I am trying to create a regieme map for some data that I have but I am having some trouble creating lines that sections the graphs and colouring each specific section. I have plotted the graph with all the infromation but the issue with the lines and colours .I have attached a photo of something similar.
thank you

采纳的回答

Kiran Felix Robert
Kiran Felix Robert 2020-7-24
Hi Ahmed,
It is my understanding that you have a set of points to plot of a graph, and you have different equations which divide the graph into different regions and you wish to partition the graph based on the equations using various colours. Assuming you know the equations which partition the graph this can be accomplished by the fill function in MATLAB. An example is also given in this answer. To apply different markers in different regions you can use logical indexing and plot separately as explained in this article. This is implemented as follows assuming some 4 dummy functions as regions and one line to be plotted across different regions,
Assume the 4 curves and lines to be as follows,
x1 = ones(1,450);
x2 = 1:5;
x3 = -1*ones(1,450);
x4 = 5*ones(1,450);
y1 = 1:450;
y2 = (4*x2).^2 + 50;
y3 = y1;
y4 = y1;
xline = -1:0.1:5;
yline = 200*ones(1,length(xline));
partitions can be made by
x1_f = [x1 fliplr(x3)]; % Creating closed are for fills
y1_f = [y1 fliplr(y1)];
x2_f = [x1 fliplr(x2)];
y2_f = [y1 fliplr(y2)];
x3_f = [x2 fliplr(x4)];
y3_f = [y2 fliplr(y4)];
plot(x1,y1,'k','LineWidth',2);
hold on
plot(x2,y2,'b','LineWidth',2);
plot(x3,y3,'r','LineWidth',2);
plot(x4,y4,'k','LineWidth',2);
fill(x1_f,y1_f,'g')
fill(x2_f,y2_f,'r')
scatter(xline(xline<1),yline(xline<1),'r*');
scatter(xline(xline>1&xline<3),yline(xline>1&xline<3),'ks')
scatter(xline(xline>3),yline(xline>3),'md')
hold off
Thanks
Kiran

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by