How to define circle size using matplotlib_venn in python

谁说胖子不能爱 提交于 2019-12-24 17:21:59

问题


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()


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/51290472/how-to-define-circle-size-using-matplotlib-venn-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!