Creating different sections in one graph

8 ビュー (過去 30 日間)
Ahmed Othman
Ahmed Othman 2020 年 7 月 21 日
コメント済み: Ahmed Othman 2020 年 7 月 24 日
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
  1 件のコメント
Ahmed Othman
Ahmed Othman 2020 年 7 月 24 日
Works perfectly!
Thank you Kiran!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by