我想绘制属于某些组的变量.
假设我有6个变量,我想要分成这3组,并绘制像维恩图.我想将变量名称注释为三个气泡.
在这个简单的例子中,我们可以说1个变量在组1中,3个变量在组2中,2个变量在组3中.
任何人都可以帮我一个简单的例子来说明如何在matplotlib中做到这一点?
我使用easy_install for matplotlib-venn时遇到问题.我在使用python2.7的Windows计算机上.我怀疑路径不正确,但我不知道如何解决这个问题.谁能帮助我?我正在尝试在CMD提示符中运行easy_install命令附加输出.
C:\Python27\Scripts>easy_install matplotlib-venn
Searching for matplotlib-venn
Reading https://pypi.python.org/simple/matplotlib-venn/
Download error on https://pypi.python.org/simple/matplotlib-venn/: [Errno 11004]
getaddrinfo failed -- Some packages may not be found!
Couldn't find index page for 'matplotlib-venn' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno 11004] getaddrinfo fai
led -- Some packages may not be found!
No local packages or download links found for matplotlib-venn
error: Could not find suitable distribution for Requirement.parse('matplotlib-ve
nn')
install …Run Code Online (Sandbox Code Playgroud) 我有以下维恩图:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
set3 = set(['C', 'D',' E', 'F', 'G'])
venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))
Run Code Online (Sandbox Code Playgroud)
看起来像这样:

如何控制绘图的字体大小?我想增加它.
使用以下代码:
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
from collections import OrderedDict
named_sets = {'x1': set(['foo','foo','bar',"pax"]), "x3" : set(['foo','qux','bar',"zoo"])}
od = OrderedDict(sorted(named_sets.iteritems()))
circlenm = ()
circlels = []
for k,v in od.iteritems():
circlenm = circlenm + (k,)
circlels.append(v)
c = venn2(subsets = circlels,set_labels = circlenm)
c.get_patch_by_id('10').set_color('red')
c.get_patch_by_id('01').set_color('blue')
c.get_patch_by_id('10').set_edgecolor('none')
c.get_patch_by_id('01').set_edgecolor('none')
c.get_patch_by_id('10').set_alpha(0.4)
c.get_patch_by_id('01').set_alpha(0.4)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我可以得到下图:

在这里,我想将“蓝色”圆圈与“红色”圆圈混合。请注意,混合的结果是棕色的。
但实际值应该是浅洋红色(下图是使用 default 创建的matplotlib_venn.venn3):

我怎样才能正确地实现这一目标?
我一直在使用 matplotlib-venn 生成 3 个集合的维恩图。如下所示。
我想问一下如何找到这些集合的交集的值。例如,与集合 A 和集合 B 相交的 384 个值是多少?与集合 A、集合 B 和集合 C 相交的 144 个值是什么?如此值得。
谢谢你。
罗德里戈

我在使用易安装或pip安装matplotlib-venn时遇到问题。我在使用python2.7的Windows计算机上。但是,cmd显示始终存在一些错误。
这是使用“ easy_install”的Windows,我在cmd中键入命令$ easy_install matplotlib-venn,然后显示错误:
"no lapack/blas resources found ".`
Run Code Online (Sandbox Code Playgroud)
然后,当我使用pip进行安装时,在cmd中键入命令$ pip install matplotlib-venn,它显示:
Command ""C:\Python27\New Folder\python.exe" -c "import setuptools, tokenize
;__file__='c:\\users\\qiu\\appdata\\local\\temp\\pip-build-cz2ob6\\scipy\\setup.
py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n'
, '\n'), __file__, 'exec'))" install --record c:\users\qiu\appdata\local\temp\pi
p-tfwzxc-record\install-record.txt --single-version-externally-managed --compile
" failed with error code 1 in c:\users\qiu\appdata\local\temp\pip-build-cz2ob6\s
cipy
Run Code Online (Sandbox Code Playgroud)
我做了一个三向维恩图.我有三个问题似乎无法解决.
移动圆圈标签的代码是什么(即"Set1","Set2","Set3")因为现在距离圆圈太远了.
将圆圈设为三个相同尺寸/更改圆圈尺寸的代码是什么?
围绕绘图移动圆圈的代码是什么.现在,set2在set3内(但颜色不同),我希望该图看起来更像是显示维恩图的"标准"方式(即3个独立的圆圈,中间有一些重叠).
另一方面,我发现很难找到诸如"set_x","set_alpha"之类的命令; 如果有人知道一本可以通过上述问题回答的手册我会很感激,我似乎无法找到一个包含我需要的所有信息的地方.
import sys
import numpy
import scipy
from matplotlib_venn import venn3,venn3_circles
from matplotlib import pyplot as plt
#Build three lists to make 3 way venn diagram with
list_line = lambda x: set([line.strip() for line in open(sys.argv[x])])
set1,set2,set3 = list_line(1),list_line(2),list_line(3)
#Make venn diagram
vd = venn3([set1,set2,set3],set_labels=("Set1","Set2","Set3"))
#Colours: get the HTML codes from the net
vd.get_patch_by_id("100").set_color("#FF8000")
vd.get_patch_by_id("001").set_color("#5858FA")
vd.get_patch_by_id("011").set_color("#01DF3A")
#Move the numbers in the circles
vd.get_label_by_id("100").set_x(-0.55)
vd.get_label_by_id("011").set_x(0.1)
#Strength of color, 2.0 is very strong.
vd.get_patch_by_id("100").set_alpha(0.8)
vd.get_patch_by_id("001").set_alpha(0.6)
vd.get_patch_by_id("011").set_alpha(0.8)
plt.title("Venn …Run Code Online (Sandbox Code Playgroud) 我想根据我的 pandas 数据框绘制维恩图。我知道matplotlib_venn接受集合作为输入。我的数据集包含客户端 ID 和另外两列,其中包含客户端是否参与活动的信息。
df_dataset = pd.read_csv('...path...',delimiter=',',decimal=',')
campaign_a = df_dataset[(df_dataset['CAM_A'] == 1)]
campaign_b = df_dataset[(df_dataset['CAM_B'] == 1)]
plt.figure(figsize=(4,4))
set1 = set(campaign_a['CLI_ID'])
set2 = set(campaign_b['CLI_ID'])
venn3([set1, set2], ('Set1', 'Set2'))
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是我收到错误:
文件“C:\Python27\Lib\site-packages\matplotlib_venn_venn3.py”,第 44 行,在compute_venn3_areas 区域 = np.array(np.abs(diagram_areas), float)
TypeError:abs() 的操作数类型错误:“set”
我可以用 matplotlib_venn 做 2 个和 3 个圆圈。任何可能绘制超过 3 的维恩图?
就我而言,我有 6 组数据并尝试用 6 个圆圈绘制维恩图
我有几个用 matplotlib-venn 库创建的不同的维恩图,它们共享至少一组。我希望该集合的圆圈大小相同,因此它们具有可比性。我还想更改标签字体的大小,但我还不明白如何从 matplotlib-venn 函数中获取它。我怎么能做到?
集合的一个例子可能是这样的:
from matplotlib_venn import venn3
s1=set('abracadabra')
s2=set('alakazam')
s3=set('stackoverflow')
s4=set('hocus pocus')
v_test1=venn3([s1,s2,s3],('set1','set2','set3'))
v_test1=venn3([s1,s3,s4],('set1','set3','set4'))
Run Code Online (Sandbox Code Playgroud) matplotlib-venn ×10
python ×10
matplotlib ×9
venn-diagram ×6
easy-install ×1
numpy ×1
pandas ×1
plot ×1
python-2.7 ×1
windows ×1