Python Matplotlib维恩图 [英] Python Matplotlib Venn diagram

查看:362
本文介绍了Python Matplotlib维恩图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to plot variables that belongs to certain groups.

说我有6个变量,我想将其分为这3组并像维恩图一样绘制.我想将变量名称注释为三个气泡.
在这个简单的示例中,我们可以说1个变量位于组1中,3个变量位于组2中,2个变量位于组3中.

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.

有人可以在matplotlib中提供一个简单的示例来帮助我吗?

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

推荐答案

matplotlib有一个漂亮的维恩图插件,名为 matplotlib-venn .从圆的大小(与设置的大小成比例)到内部和外部标签,看起来都可以完全自定义以执行所需的操作.

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.

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

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

编辑:根据下面的注释,以下代码使用相同的库为文本提供了不重叠的圆圈:

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

给出图表:

这篇关于Python Matplotlib维恩图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆