How can I plot phase diagrams in MATLAB?
91 次查看(过去 30 天)
显示 更早的评论
Is it possible to plot phase diagrams as the attached ones using MATLAB?
Thanks!
2 个评论
DGM
2022-3-19
Do you have any data to describe the boundaries?
If you do, you might start with fill() or patch().
采纳的回答
Voss
2022-3-19
Here's how you might produce something similar to 2.jpg:
p = [0.13 0.26 0.42 0.52]; % adjust these points along the curve to your liking
g = [1 0.8 0.4 0 ];
patch([0 p 0],g([1 1:end end]),[246 173 203]/255);
patch(p([1:end end]),g([1:end 1]),[255 249 173]/255);
patch([p([end end]) 1 1],g([1 end end 1]),[204 231 212]/255);
line(p,g,'Color',[0 0 0],'LineWidth',1.5);
text(0.67,0.44,'Regime I','Color',[93 48 107]/255,'FontSize',14);
text(0.33,0.82,'Regime II','Color',[93 48 107]/255,'FontSize',14);
text(0.07,0.42,'Regime III','Color',[93 48 107]/255,'FontSize',14);
text(0.9,0.9,'(c)','FontSize',16);
xlabel('p');
ylabel('\gamma');
set(gca(),'FontSize',12,'FontWeight','bold','XTick',0:0.1:1,'YTick',0:0.2:1);
3 个评论
Voss
2022-3-20
You have the right idea, which is to write down the x,y coordinates of the points along the edges of a patch in order. What you are missing is that you have to essentially go all the way around the perimeter of the patch. That is, you must include the points where the patch goes to the x- and/or y-axis or otherwise to the edge of the plot region. See my comments in the code below, explaining in slightly more detail for this particular case.
% I added one point here at (0.95, 0.95) to get the patch to extend to the
% upper-right corner of the plot
a1 = [0.45 0.45 0.5 0.55 0.55 0.6 0.65 0.65 0.7 0.7 0.75 0.75 0.8 0.85 0.9 0.9 0.95 0.95];
p1 = [0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35 0.3 0.3 0.25 0.25 0.95];
% then use those same points - except for the corner one I added -
% for the yellow patch, since all those points are common to
% the green patch as well, along the boundary between yellow and green
a2 = [0.05 a1(1:end-1) 0.95 0.05];
p2 = [0.95 p1(1:end-1) 0.05 0.05];
% red patch makes an L-shape
a3 = [0 0 0.05 0.05 0.95 0.95];
p3 = [0 0.95 0.95 0.05 0.05 0 ];
% a2 = [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95];
% p2 = [0.05 0.95 0.95 0.95 0.95 0.95 0.95 0.9 0.85 0.8 0.7 0.65 0.55 0.45 0.35 0.3 0.25 0.25 0.25];
% % a3 = [0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95];
% % p3 = [0.95 0.95 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05];
% a3 = [.05 0.05];
% p3 = [0.95 0.05];
patch(a3,p3,[246 173 203]/255);
patch(a2,p2,[255 249 173]/255);
patch(a1,p1,[204 231 212]/255);
text(0.8,0.7,'Regime I','Color',[93 48 107]/255,'FontSize',14);
text(0.4,0.42,'Regime II','Color',[93 48 107]/255,'FontSize',14);
text(0.02,0.42,'Regime III','Color',[93 48 107]/255,'FontSize',14);
text(0.9,0.9,'(c)','FontSize',16);
xlabel('\alpha');
ylabel('P');
set(gca(),'FontSize',12,'FontWeight','bold','XTick',0:0.2:1,'YTick',0:0.2:1);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!