Skip to main content
 首页 » 编程设计

Python:matplotlib-venn之如何调整位置/移动维恩图圆圈内的值

2025年05月04日23telwanggs

这是维恩图示例:

from matplotlib import pyplot as plt 
import numpy as np 
from matplotlib_venn import venn3, venn3_circles 
plt.figure(figsize=(4,4)) 
vd = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C')) 
 
plt.show() 

请您参考如下方法:

我通过查看这个问题中的代码弄明白了这一点:Venn3: How to reposition circles and labels?

具体来说,这部分:

vd.get_label_by_id("100").set_x(1.55) 

将它们放在一起(看看现在 1 是如何一直到右边...):

from matplotlib import pyplot as plt 
import numpy as np 
from matplotlib_venn import venn3, venn3_circles 
plt.figure(figsize=(4,4)) 
vd = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C')) 
 
#Move the numbers in the circles                                                                                                                                                
vd.get_label_by_id("100").set_x(1.55) 
 
plt.show() 

关于这个数字,似乎还有很多其他的事情可以设置。可以通过运行找到所有适用的可调用方法的完整列表:

x = venn_diagram.get_label_by_id("100") 
dir(x)