【问题标题】:Visualise 2 data frame columns with True or False values as a Venn diagram using Python? Truth table to Venn diagram?使用 Python 将具有 True 或 False 值的 2 个数据框列可视化为维恩图?真值表到维恩图?
【发布时间】:2020-10-13 11:27:56
【问题描述】:

我正在尝试可视化一个由 True 和 False 值组成的数据框,我想创建一个维恩图来比较这些并根据 a 和 b 的交集计数显示为真,只有 a 为真,只有 b 为真,而外面不是 a 或 b。 Please find the image for the corresponding Venn diagram attached.

|---------------------|------------------|
|          A          |         B        |
|---------------------|------------------|
|        True         |      False       |
|---------------------|------------------|
|        True         |      False       | 
|---------------------|------------------|
|        True         |      False       |
|---------------------|------------------|
|        True         |      True        |
|---------------------|------------------|
|        False        |      False       |
|---------------------|------------------|
|        False        |      False       |
|---------------------|------------------|
|        False        |      True        |
|---------------------|------------------|
|        True         |      False       |
|---------------------|------------------|

【问题讨论】:

  • 你能提供代码来重现你的数据框吗?

标签: python diagram


【解决方案1】:

这个matplotlib_venn似乎有一个特殊的包。

import matplotlib.pyplot as plt
from matplotlib_venn import venn2

# Create the numbers for the diagram
# This will depend on the format of your A and B, I'm assuming numpy arrays
only_a = sum(A & ~B)
only_b = sum(B & ~A)
a_and_b = sum(A & B)

venn2(subsets = (only_a, only_b, a_and_b), set_labels = ('Group A', 'Group B'))

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2013-11-19
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 2023-01-14
    • 1970-01-01
    相关资源
    最近更新 更多