Python Matplotlib 维恩图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19841535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:46:52  来源:igfitidea点击:

Python Matplotlib Venn diagram

pythonmatplotlibvenn-diagrammatplotlib-venn

提问by jonas

I want to plot variables that belongs to certain groups.

我想绘制属于某些组的变量。

Say that I have 6 variables that I want to sort into these 3 groups and plot like a venn diagram. I would like to annotate the variable names into the three bubbles.
In this simple example we could say that 1 variable is in group 1, 3 variables in group 2 and 2 variables in group 3.

假设我有 6 个变量,我想将它们分为这 3 个组并像维恩图一样绘制。我想将变量名称注释到三个气泡中。
在这个简单的例子中,我们可以说第 1 组中有 1 个变量,第 2 组中有 3 个变量,第 3 组中有 2 个变量。

Could anyone help me with a simple example of how to do it in matplotlib?

谁能帮我举一个简单的例子来说明如何在 matplotlib 中做到这一点?

采纳答案by Hooked

There is a beautiful Venn diagram add-on for matplotlib called matplotlib-venn. It looks like it can be completely customized to do what you are looking for, from the size of the circles (proportional to the set size), to inner and outer labels.

matplotlib 有一个漂亮的维恩图插件,称为matplotlib-venn。从圆圈的大小(与设置的大小成比例)到内部和外部标签,它看起来可以完全自定义以执行您要查找的内容。

Using the example code on the website gives a plot like:

使用网站上的示例代码给出如下图:

enter image description here

在此处输入图片说明

Edit:Per the comments below the following code gives non-overlapping circles with text using the same library:

编辑:根据下面的评论,以下代码使用相同的库给出了带有文本的非重叠圆圈:

import pylab as plt
from matplotlib_venn import venn3, venn3_circles

v = venn3(subsets=(1,1,0,1,0,0,0))
v.get_label_by_id('100').set_text('First')
v.get_label_by_id('010').set_text('Second')
v.get_label_by_id('001').set_text('Third')
plt.title("Not a Venn diagram")
plt.show()

Gives the diagram:

给出图:

enter image description here

在此处输入图片说明