Add legend item for overlapping semitransparent patch regions
조회 수: 6 (최근 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!