Add legend item for overlapping semitransparent patch regions
9 ビュー (過去 30 日間)
古いコメントを表示
I am trying to figure out if there is a way to create a new legend item for region of overlap between two semitransparant patch objects. Looking at the semitransparent example on the patch page, it shows how patches can overlap. Below, I took the example and changed it so that the red patch is a lot less visible. I would now want a legend that says something like "condition 1", "condition 2" and "conditions 1 and 2". I want to add this to make the plot more clear to someone with colorblindness who might have trouble inferring the overlap.
Ideally adding this 3rd legend object this could be done without searching for the overlap region and making a 3rd patch. Im not sure if this is actually possible though currently in Matlab.
v1 = [2 4; 2 8; 6 6.5];
f1 = [1 2 3];
figure
patch('Faces',f1,'Vertices',v1,'FaceColor','red','FaceAlpha',.3);
v2 = [2 4; 2 8; 8 8];
f2 = [1 2 3];
patch('Faces',f2,'Vertices',v2,'FaceColor','blue','FaceAlpha',.5);
0 件のコメント
採用された回答
Shivam Singh
2021 年 8 月 20 日
As per my knowledge, MATLAB does not have a direct function to implement the legend of overlapping semi-transparent patch regions, because I think that finding overlap is not the intended property of "patch".
But you can figure out the overlapping shape and add legend to it. The following code might help you:
v1 = [2 4; 2 8; 6 6.5];
f1 = [1 2 3];
p1=patch('Faces',f1,'Vertices',v1,'FaceColor','red','FaceAlpha',.3);
v2 = [2 4; 2 8; 8 8];
f2 = [1 2 3];
p2=patch('Faces',f2,'Vertices',v2,'FaceColor','blue','FaceAlpha',.5);
%Finding intersection of two shapes V1 and V2
polyout = intersect(polyshape(v1),polyshape(v2));
%Creating a patch of the overlapping shape of p1 and p2
p_inter=patch(polyout.Vertices(:,1),polyout.Vertices(:,2),'k');
legend("p1","p2","p_intersection");
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!