# 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.