3

I'm using python package matplotlib_venn to plot venn diagram. I want to set the size of the circles such that in different plots the circle size will be the same. How could I do it?

from charticle.venn import Venn2
import matplotlib_venn as vplt
import matplotlib.pyplot as plt
fig = plt.figure()
plt.subplot(121)
v2 = vplt.venn2(subsets={'10':10,'01':10,'11':1},set_labels = ('A','B'))
v.Sizes(a=1.0, b=10.0, ab=1.0)
plt.subplot(122)
v1 = vplt.venn2(subsets={'10':10,'01':1000,'11':1},set_labels = ('A','B'))
plt.show()

enter image description here

CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
jonathan
  • 31
  • 1
  • 4
  • Please [don't post pictures of code or error messages](http://idownvotedbecau.se/imageofcode), post the text directly here on SO instead. – Mr. T Jul 30 '18 at 07:51

2 Answers2

1

How's this? I mostly worked with the venn2_circles objects and ignored the venn2 ones. If you try to color in with the venn2 object, the radii will be off and it won't fill properly, which is what I think the comment above was mentioning.

import matplotlib_venn as vplt
import matplotlib.pyplot as plt

plt.figure(figsize=(10,10))
plt.subplot(1, 2, 1)
plt.title('Subplot 1')
v = vplt.venn2(subsets=(10,10,1), set_labels=('A', 'B'), set_colors=('w', 'w'))
c = vplt.venn2_circles(subsets=(2, 2, 1), linestyle='solid')
c[0].set_radius(0.32)
c[1].set_radius(0.32)
c[0].set_lw(2.0)
c[1].set_lw(2.0)
c[0].set_color('green')
c[1].set_color('red')
c[0].set_alpha(0.5)
c[1].set_alpha(0.5)
c[0].set_edgecolor('black')
c[1].set_edgecolor('black')

plt.subplot(1, 2, 2)
plt.title('Subplot 2')
v = vplt.venn2(subsets=(10,1000,1), set_labels=('A', 'B'), set_colors=('w', 'w'))
v.get_label_by_id('10').set_x(0.25)
v.get_label_by_id('01').set_x(-.25)
v.get_label_by_id('11').set_x(0)
v.set_labels[0].set_position((-0.22, -0.45))
v.set_labels[1].set_position((0.25, -0.45))


c = vplt.venn2_circles(subsets=(2, 2, 1), linestyle='solid')
c[0].set_radius(0.32)
c[1].set_radius(0.32)
c[0].set_lw(2.0)
c[1].set_lw(2.0)
c[0].set_color('green')
c[1].set_color('red')
c[0].set_alpha(0.5)
c[1].set_alpha(0.5)
c[0].set_edgecolor('black')
c[1].set_edgecolor('black')

Picture of result here because I need 10 reputation to post pictures

  • Perfect! Plug and play to control circle size, overlap, colours of venn diagram. It could almost be a package itself. Even the link is still functional. Yet somehow, three years later not accepted, and not a single upvote!!! Thank you Mr Christy! – DrWhat Nov 23 '22 at 08:51
  • Hey, thank you! Entirely forgot about this, but glad to hear someone found it helpful! – Tim Christy Dec 04 '22 at 03:03
0

You can not do it.

The functions venn2_circles and venn3_circles return the list of matplotlib.patch.Circle objects that may be tuned further to your liking.

This means that circles radii and centers are linked to each other therefore changing of center or radius may cause the problem.

More info: https://pypi.org/project/matplotlib-venn/ and https://stackoverflow.com/a/46008924/7390366

pcu
  • 1,204
  • 11
  • 27