# Matplotlib 维恩图

Salman Mehmood 2024年2月15日

## 在 Python 中使用 Matplotlib 创建维恩图

Matplotlib 库使你能够使用某些特定函数生成两个圆和三圆维恩图。使用特定命令，我们可以为维恩图生成加权、未加权和可调的圆。

``````pip install matplotlib-venn
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn2, venn2_circles, venn2_unweighted

items = [80, 43, 6]
labels = ["set1", "set2"]
``````

`venn2()` 函数是生成圆圈的加权图，其大小取决于我们在此项目列表中给出的值。这个函数有几个参数。

``````venn2(subsets=items, set_labels=labels, set_colors=("red", "green"), alpha=0.7)
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn2, venn2_circles, venn2_unweighted

items = [80, 43, 6]
labels = ["set1", "set2"]
venn2(subsets=items, set_labels=labels, set_colors=("red", "green"), alpha=0.7)
plot.title("2 weighted venn diagram")
plot.show()
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn2, venn2_circles, venn2_unweighted

items = [80, 43, 6]
labels = ["set1", "set2"]
venn2_unweighted(
subsets=items, set_labels=labels, set_colors=("red", "green"), alpha=0.5
)
plot.title("2 unweighted venn diagram")
plot.show()
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn2, venn2_circles, venn2_unweighted

items = [80, 43, 6]
labels = ["set1", "set2"]
venn2_circles(subsets=items)
plot.title("2 circles venn diagram")
plot.show()
``````

``````items=[a,b,ab,c,ac,bc,abc]
``````

``````items = [80, 43, 6, 62, 16, 3, 18]
labels = ["set1", "set2", "set3"]
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn3, venn3_unweighted

items = [80, 43, 6, 62, 16, 3, 18]
labels = ["set1", "set2", "set3"]

venn3(subsets=items, set_labels=labels, alpha=0.6)
plot.title("3 weighted venn diagram")
plot.show()
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn3, venn3_unweighted

items = [80, 43, 6, 62, 16, 3, 18]
labels = ["set1", "set2", "set3"]

venn3_unweighted(subsets=items, set_labels=labels, alpha=0.6)
plot.title("3 unweighted venn diagram")

plot.show()
``````

``````import matplotlib.pyplot as plot
from matplotlib_venn import venn3_circles

items = [80, 43, 6, 62, 16, 3, 18]
labels = ["set1", "set2", "set3"]

venn3_circles(subsets=items, linestyle="dashed")
plot.title("3 circle venn diagram")

plot.show()
``````

Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.