Skip to content

Commit

Permalink
fixed label order and updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
manhowong committed Apr 19, 2023
1 parent f36c560 commit bc4ff31
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ Input : n [positive integer]
An array of set names in left-to-right order
labels [string | char | cellstr | numeric]
An array of label names for labeling each section;
For Set A, B, C and D, there are 15 sections: A, B, C, D,
A&B, A&C, A&D, B&C, B&D, C&D, A&B&C, A&B&D, A&C&D, B&C&D,
A&B&C&D. Elements in 'labels' must follow the above order,
e.g. for Set A and B, the label order should be A, B,
A&B; Any extra labels will be ignored.
Elements in the array must follow the following order:
For diagram with Set A and B, labels for 3 sections are
A, B and A&B.
For diagram with Set A, B and C, labels for 7 sections are
A, B, C, D, A&B, A&C, B&C and A&B&C.
For diagram with Set A, B, C and D, labels for 15 sections
are A, B, C, D, A&B, A&C, A&D, B&C, B&D, C&D, A&B&C, A&B&D
, A&C&D, B&C&D, A&B&C&D.
Any extra labels will be ignored.
colors [rows of RGB triplet]
Color map for fill colors in left-to-right order.
e.g. [1 0 0; 0 1 0; 0 0 1] represents red, green, blue;
Expand Down Expand Up @@ -63,23 +67,23 @@ mylabels = randi(100,[15,1]);
Draw two sets with labels; set fill alpha (transparency) to 0.7, set label color to white and use black edges with custom thickness:

```
venn(2,sets=mysets,labels=mylabels,alpha=0.7,edgeC=[0 0 0],labelC=[1 1 1],edgeW=5);
venn(2,'sets',mysets,'labels',mylabels,'alpha',0.7,'edgeC',[0 0 0],'labelC',[1 1 1],'edgeW',5);
```
![2sets](resources/2sets.png)


Draw three sets with labels; set fill alpha to 0 and use black edges with custom thickness:

```
venn(3,sets=mysets,labels=mylabels,alpha=0,edgeC=[0 0 0],edgeW=3);
venn(3,'sets',mysets,'labels',mylabels,'alpha',0,'edgeC',[0 0 0],'edgeW',3);
```
![3sets2](resources/3sets2.png)

Draw four sets with labels; use custom color map, set alpha to 0.5 and use white edges with custom thickness:

```
c = summer(4);
venn(4,sets=mysets,labels=mylabels,colors=c,alpha=0.5,edgeC=[1 1 1],edgeW=3);
venn(4,'sets',mysets,'labels',mylabels,'colors',c,'alpha',0.5,'edgeC',[1 1 1],'edgeW',3);
```
![4sets](resources/4sets.png)

Expand Down
65 changes: 42 additions & 23 deletions venn.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
% An array of set names in left-to-right order
% labels [string | char | cellstr | numeric]
% An array of label names for labeling each section;
% For Set A, B, C and D, there are 15 sections: A, B, C, D,
% A&B, A&C, A&D, B&C, B&D, C&D, A&B&C, A&B&D, A&C&D, B&C&D,
% A&B&C&D. Elements in 'labels' must follow the above order,
% e.g. for Set A and B, the label order should be A, B,
% A&B; Any extra labels will be ignored.
% Elements in the array must follow the following order:
% For diagram with Set A and B, labels for 3 sections are
% A, B and A&B.
% For diagram with Set A, B and C, labels for 7 sections are
% A, B, C, D, A&B, A&C, B&C and A&B&C.
% For diagram with Set A, B, C and D, labels for 15 sections
% are A, B, C, D, A&B, A&C, A&D, B&C, B&D, C&D, A&B&C, A&B&D
% , A&C&D, B&C&D, A&B&C&D.
% Any extra labels will be ignored.
% colors [rows of RGB triplet]
% Color map for fill colors in left-to-right order.
% e.g. [1 0 0; 0 1 0; 0 0 1] represents red, green, blue;
Expand Down Expand Up @@ -86,24 +90,39 @@
end

% for code readability, assign v to variables named by letters
A = v(1);
B = v(2);
C = v(3);
D = v(4);

AB = v(5);
AC = v(6);
AD = v(7);
BC = v(8);
BD = v(9);
CD = v(10);

ABC = v(11);
ABD = v(12);
ACD = v(13);
BCD = v(14);

ABCD = v(15);
switch n
case 2
A = v(1);
B = v(2);
AB = v(3);
case 3
A = v(1);
B = v(2);
C = v(3);
AB = v(4);
AC = v(5);
BC = v(6);
ABC = v(7);
case 4
A = v(1);
B = v(2);
C = v(3);
D = v(4);

AB = v(5);
AC = v(6);
AD = v(7);
BC = v(8);
BD = v(9);
CD = v(10);

ABC = v(11);
ABD = v(12);
ACD = v(13);
BCD = v(14);

ABCD = v(15);
end

% figure settings
vennfig = figure('Position',[20 20 800 450],'Color','w');
Expand Down

0 comments on commit bc4ff31

Please sign in to comment.