matplotlib 如何平滑维恩图边缘

p4tfgftt  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(107)

我有一个用Python创建的维恩图,但我不知道如何平滑所有的边缘(也包括内部的边缘)。

我的代码:

import matplotlib.pyplot as plt
from matplotlib_venn import venn3
from matplotlib.patches import PathPatch
from matplotlib.path import Path

set1 = {i for i in range(150)}
set2 = {i for i in range(150 - 75, 350 - 75)}
set3 = {i for i in range(150 - 75, 150 - 75 + 20)}

fig, ax = plt.subplots()
venn = venn3([set1, set2, set3], set_labels=('', '', ''))

circle1 = venn.get_patch_by_id('100')
circle2 = venn.get_patch_by_id('010')
circle3 = venn.get_patch_by_id('110')
circle4 = venn.get_patch_by_id('111')

circle1.set_edgecolor('none')
circle2.set_edgecolor('none')
circle3.set_edgecolor('none')
circle4.set_edgecolor('none')

path_data1 = circle1.get_path().vertices.tolist()
patch1 = PathPatch(Path(path_data1), facecolor='yellow', edgecolor='#d6d3d6', hatch='/', lw=0)
ax.add_patch(patch1)

path_data2 = circle2.get_path().vertices.tolist()
patch2 = PathPatch(Path(path_data2), facecolor='purple', edgecolor='#d6d3d6', hatch='\\', lw=0)
ax.add_patch(patch2)

path_data3 = circle3.get_path().vertices.tolist()
patch3 = PathPatch(Path(path_data3), facecolor='pink', edgecolor='#d6d3d6', hatch="\/", lw=0)
ax.add_patch(patch3)

path_data4 = circle4.get_path().vertices.tolist()
patch4 = PathPatch(Path(path_data4), facecolor='orange', edgecolor='#d6d3d6', hatch=".", lw=0)
ax.add_patch(patch4)

venn.get_label_by_id('100').set_text('')
venn.get_label_by_id('010').set_text('')
venn.get_label_by_id('110').set_text('')
venn.get_label_by_id('111').set_text('')

# Show the plot
plt.axis('off')
plt.show()

如何做到这一点?
这里的棱角是什么造成的

cdmah0mi

cdmah0mi1#

您仅使用matplotlib-vern返回的“圆”的顶点初始化PathPatch对象。如果没有显式代码,PathPatch默认为LINETO,即在顶点之间绘制直线。您将需要同时使用顶点和代码来初始化PathPatch示例。

path_data1 = circle1.get_path()
patch1 = PathPatch(path_data1, facecolor='yellow', edgecolor='#d6d3d6', hatch='/', lw=0)
# etc

相关问题