Add legend item for overlapping semitransparent patch regions
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Emma Farnan
il 9 Ago 2021
Risposto: Shivam Singh
il 20 Ago 2021
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 Commenti
Risposta accettata
Shivam Singh
il 20 Ago 2021
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!