Code covered by the BSD License

### Highlights from venn

4.66667
4.7 | 14 ratings Rate this file 48 Downloads (last 30 days) File Size: 11.3 KB File ID: #22282 Version: 1.7

# venn

by

### Darik (view profile)

30 Nov 2008 (Updated )

Plot 2- or 3- circle area-proportional Venn diagram

File Information
Description

VENN Plot 2- or 3- circle area-proportional Venn diagram

VENN offers the following advantages over the VennX function available on the FEX:
1) It's much faster
2) Draws venn diagram as patch objects, allowing much greater flexibility in presentation (edge/face colors, transparency, etc.)
3) Returns a structure with required plotting data, allowing the user to make additional modifications (translation, scaling, rotation, etc.)
4) Supports multiple methods for optimizing the position of three-circle venn diagrams.

venn(A, I)
venn(Z)
venn(..., 'ErrMinMode', MODE)
H = venn(...)
[H, S] = venn(...)
[H, S] = venn(..., 'Plot', 'off')
S = venn(..., 'Plot', 'off')
[...] = venn(..., P1, V1, P2, V2, ...)

venn(A, I) by itself plots circles with total areas A, and intersection area(s) I. For two-circle venn diagrams, A is a two element vector of circle areas [c1 c2] and I is a scalar specifying the area of intersection between them. For three-circle venn diagrams, A is a three element vector [c1 c2 c3], and I is a four element vector [i12 i13 i23 i123], specifiying the two-circle intersection areas i12, i13, i23, and the three-circle intersection i123.

venn(..., 'ErrMinMode', MODE)
Used for 3-circle venn diagrams only. MODE can be 'TotalError' (default), 'None', or 'ChowRodgers'. When ErrMinMode is 'None', the positions and sizes of the three circles are fixed by their pairwise-intersections, which means there may be a large amount of error in the area of the three-circle intersection. Specifying ErrMinMode as 'TotalError' attempts to minimize the total error in all four intersection zones. The areas of the three circles are kept constant in proportion to their populations. The 'ChowRodgers' mode uses the the method proposed by Chow and Rodgers [Ref. 1] to draw 'nice' three-circle venn diagrams which appear more visually representative of the desired areas, although the actual areas of the circles are allowed to deviate from requested values.

H = venn(...) returns a two- or three- element vector of handles to the patches representing the circles.

[H, S] = venn(...) returns a structure containing descriptive valuescomputed for the requested venn diagram.

[...] = venn(..., P1, V1, P2, V2, ...) Specifies additional patch settings in standard Matlab parameter/value pair syntax. Parameters can be any valid patch parameter. Values for patch parameters can either be single values, or a cell array of length LENGTH(A), in which case each value in the cell array is applied to the corresponding circle in A.

See venn.m for additional options, descriptions, references, and examples.

Acknowledgements

Proportional Venn Diagrams inspired this file.

MATLAB release MATLAB 7.7 (R2008b)
14 May 2015 cmo

### cmo (view profile)

23 Sep 2014 Matthew

### Matthew (view profile)

18 Sep 2014 Tong Sheng

### Tong Sheng (view profile)

With regards to "When I put text onto the graph (suppose for simplicity I want to put the amount % of each zone in each zone centroid), when I set a transparency (alpha <1), the text becomes faded as if the circles were covering it."

Just to update, this is no longer an issue when I export the figure as jpg, etc.; the text appears opaque and not covered by the patches.

18 Sep 2014 Tong Sheng

### Tong Sheng (view profile)

Thank you, Darik. I will give that a try.

Another comment/question: when I put text onto the graph (suppose for simplicity I want to put the amount % of each zone in each zone centroid), when I set a transparency (alpha <1), the text becomes faded as if the circles were covering it. Ideally I would like the text to be bold and clear on top of the semi-transparent circles. Anyone else have this same problem, or know of a workaround? Thanks.

Comment only
08 Sep 2014 Darik

### Darik (view profile)

@Tong: I suppose you could tweak the position of the circles manually via the returned handles:

%Build the venn plot and return the handles
h = venn(...)

%Shift the first circle by (dx, dy)
set(h(1), 'XData', dx + get(h(1), 'XData'))
set(h(1), 'YData', dy + get(h(1), 'YData'))

Comment only
05 Sep 2014 Tong Sheng

### Tong Sheng (view profile)

I have a 3-circle diagram in which one of my zones is empty (for [z1 z2 z3 z12 z13 z23 z123], z1 = 0), but an area/patch is still drawn. I think if the centroid for circle1 is shifted so that it fits completely inside the other two circles, that would be ok. How can I do this?

Comment only
23 Aug 2014 Fabiano Baroni

### Fabiano Baroni (view profile)

great work, thanks.

I noticed that sometimes this error is returned: "Triangle inequality not satisfied", for example if A=[15 14 3]; I=[13 1 0 0].

It seems to be related to the constrain that circle centres shall not be further apart than rA+rB:

D = fminbnd(@areadiff, 0, rA+rB, opts);

Can you please suggest a solution or a workaround for this issue? Many thanks.

Comment only
19 Sep 2013 Hiren

### Hiren (view profile)

11 Sep 2013 Eugene Gallagher

### Eugene Gallagher (view profile)

Thanks Darik. You were right. My 2013a had a faulty Matlab path statement and wasn't finding my optimization toolbox. I changed back to the default path, rebuilt my path for my directories, and Venn.m worked beautifully. Thanks.

Comment only
06 Sep 2013 Darik

### Darik (view profile)

Eugene: optimset is a function in the optimization toolbox. I suspect you have that toolbox installed in your Matlab 2012, but not 2013.

Comment only
03 Sep 2013 Eugene Gallagher

### Eugene Gallagher (view profile)

While the function works great in Matlab Release 2012a, it produces errors in Release 2013a:
>> figure, axis equal, axis off;A=[100 100];I=25;venn(A,I,'FaceColor',{'r','y'},'FaceAlpha',{1,0.6},'EdgeColor','black')

Undefined function 'optimset' for input arguments of type 'char'.

Error in venn>parseArgsIn (line 860)
fminOpts = [optimset('fminbnd'), optimset('fminsearch')];

Error in venn (line 166)
[A0, I0, Z0, nCirc, fminOpts, vennOpts, patchOpts] = parseArgsIn (varargin);

Comment only
22 Mar 2013 Darik

### Darik (view profile)

@RyanG sure, just set the intersection between those two circles equal to the area of the smaller (enclosed) circle. But depending on the area of the third circle and its intesections, a solution may not be possible.

Comment only
22 Mar 2013 Ryan G

### Ryan G (view profile)

Is it possible to create a 3-circle venn diagram such that 1 circle is entirely inside another?

05 Dec 2012 Darik

### Darik (view profile)

the cyclist: that would be a pretty embarrassing bug on my part. what about circles drawn by other functions, like:

cla, rectangle('Curvature', [1 1], 'Position', [0 0 1 1]); axis equal

?

Comment only
04 Dec 2012 the cyclist

### the cyclist (view profile)

Great function. Seems to work just as advertised (in my limited trial). However, the areas don't look quite circular to me, whether or not I apply "axis square" after running venn.

Is that expected? I am using R2012b.

14 Nov 2012 Rob Campbell

13 Mar 2012 Matt

### Matt (view profile)

18 May 2011 moggces

### moggces (view profile)

[h, s] = venn([49, 58, 108], [33, 1, 17, 0], 'ErrMinMode', 'ChowRodgers');
This will prompt errors and can't generate h and s variables.

Comment only
11 Mar 2011 Jeremy

### Jeremy (view profile)

Nevermind my last comment. As long as you center the text labels vertically and horizontally, the zone centroids work quite well. Nice work!

Comment only
08 Mar 2011 Jeremy

### Jeremy (view profile)

Great job on the function. My only beef is that the zone centroids don't seem to be quite accurate.

14 Feb 2011 Darik

### Darik (view profile)

Hi Yuri,

You can try the ChowRodgers mode, which adjusts area ratios instead of absolute areas, and seems to give more satisfying results when actual solutions are impossible. Unfortunately when I tried your dataset I found a small bug in the code -- I just submitted a fix, but it will take a day or two to show up on FEX. If you want you can just fix it yourself: line 563 says:

x = NaN; y = NaN;

It should be edited to include:

x = NaN; y = NaN; sinTp = NaN; cosTp = NaN;

Then you can plot the approximate venn diagram with

venn([477 487 370 3 54 5 2], 'ErrMinMode', 'ChowRodgers')

Comment only
14 Feb 2011 Yuri K

### Yuri K (view profile)

Trying to build venn diagram with the vector v=[477 487 370 3 54 5 2];
Without any additional parameters I've got an error:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: Inf
Worked only with
venn(v,'ErrMinMode','None');
but didn't get any 123 intersection. No problem with vennX, but I really like the idea of vector graphics.
I don't need exact proportions, something close would be good enough.

Comment only
06 Sep 2010 Omar

### Omar (view profile)

13 Jan 2010 Eran Mukamel

### Eran Mukamel (view profile)

Thanks for the bug fix!

10 Jan 2010 Darik

### Darik (view profile)

Hey Eran, can you paste the error you get? Also what version of Matlab are you using?

Comment only
10 Jan 2010 Eran Mukamel

### Eran Mukamel (view profile)

Functionality of syntax: [H, S] = venn(...) does not work for me.

02 Apr 2009 Or Zuk

### Or Zuk (view profile)

30 Mar 2009 Darik

### Darik (view profile)

Hi Or,

You can do this with the returned structure:

[H, S] = venn(...)
for i = 1:length(S.ZoneCentroid)
text(S.ZoneCentroid(i,1), S.ZoneCentroid(i,2), num2str(S.ZonePop(i)));
end

Comment only
30 Mar 2009 Or Zuk

### Or Zuk (view profile)

Works great.

The only thing missing (which appears in VennX) is a display
the sizes of each set on the venn diagram itself. Is it easy to add this?

03 Apr 2009 1.3

Fixed a bug found by Or Zuk (bug report via email) where zone centroids weren't properly calculated for two-set diagrams.

12 Jan 2010 1.4

Fixed a bug found by Eran Mukamel where zone centroids in the returned structure were miscalculated in some cases.

12 Jan 2010 1.6

Fixed a typo in the help comments

14 Feb 2011 1.7

Bugfix: ChowRodgers mode failed when initial guess had zero three circle intersection