我如何选择(select)维恩图区域
How i can pick(select) venn diagram area
是否可以通过单击 python 来选择或 select 维恩图区域?
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles
plt.figure(figsize=(4,4))
v = venn3(subsets=(1, 2, 3, 4, 5, 6, 7), set_labels = ('A', 'B', 'C'))
c = venn3_circles(subsets=(1, 2, 3, 4, 5, 6, 7), linestyle='dashed')
plt.title("Sample Venn diagram")
plt.show()
Matplotlib 确实支持 some degree of event handling 以及绘图组件的 "pick" 事件(无论是维恩图还是任何其他类型的绘图)。
从 venn3
函数返回的维恩图对象包含一个字段 patches
,它列出了构成该图的所有 PathPatch
对象。您可以将这些 "pickable" 设置为任何其他 Matplotlib 补丁对象:
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3
# Create the diagram
plt.figure(figsize=(4,4))
v = venn3(subsets=(1, 2, 3, 4, 5, 6, 7), set_labels = ('A', 'B', 'C'))
plt.title("Sample Venn diagram")
# Make all patches of the diagram pickable
for p in v.patches:
if p is not None: p.set_picker(True)
# This is the event handler
def on_pick(event):
p = event.artist
ec = p.get_edgecolor()
p.set_edgecolor('black' if ec[-1] == 0.0 else 'none')
plt.gcf().canvas.draw() # Redraw plot
# Connect event handler
plt.gcf().canvas.mpl_connect('pick_event', on_pick)
# Show the plot
plt.show()
venn3_circles
函数 returns 三个 Circle
补丁的列表,绘制在 "properly segmented" 图上。您也可以将它们设置为可拾取的,但是您需要以某种方式处理 "pick conflicts" 。因此,一般来说,我建议您使用 venn3
(如果您需要 7 个色块)或 venn3_circles
(如果您只需要三个圆圈),但不要同时使用。
是否可以通过单击 python 来选择或 select 维恩图区域?
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles
plt.figure(figsize=(4,4))
v = venn3(subsets=(1, 2, 3, 4, 5, 6, 7), set_labels = ('A', 'B', 'C'))
c = venn3_circles(subsets=(1, 2, 3, 4, 5, 6, 7), linestyle='dashed')
plt.title("Sample Venn diagram")
plt.show()
Matplotlib 确实支持 some degree of event handling 以及绘图组件的 "pick" 事件(无论是维恩图还是任何其他类型的绘图)。
从 venn3
函数返回的维恩图对象包含一个字段 patches
,它列出了构成该图的所有 PathPatch
对象。您可以将这些 "pickable" 设置为任何其他 Matplotlib 补丁对象:
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3
# Create the diagram
plt.figure(figsize=(4,4))
v = venn3(subsets=(1, 2, 3, 4, 5, 6, 7), set_labels = ('A', 'B', 'C'))
plt.title("Sample Venn diagram")
# Make all patches of the diagram pickable
for p in v.patches:
if p is not None: p.set_picker(True)
# This is the event handler
def on_pick(event):
p = event.artist
ec = p.get_edgecolor()
p.set_edgecolor('black' if ec[-1] == 0.0 else 'none')
plt.gcf().canvas.draw() # Redraw plot
# Connect event handler
plt.gcf().canvas.mpl_connect('pick_event', on_pick)
# Show the plot
plt.show()
venn3_circles
函数 returns 三个 Circle
补丁的列表,绘制在 "properly segmented" 图上。您也可以将它们设置为可拾取的,但是您需要以某种方式处理 "pick conflicts" 。因此,一般来说,我建议您使用 venn3
(如果您需要 7 个色块)或 venn3_circles
(如果您只需要三个圆圈),但不要同时使用。