matplotlib pyplot - 大小与数据成比例的子图

matplotlib pyplot - subplots with sizes proportional to the data

我想创建一个带有子图的图形,其中每个子图的大小与其包含的数据成正比。例如:

from matplotlib import pyplot as plt
from matplotlib_venn import venn2
data_dict = {'foo': (10,7,5), 'bar': (2,6,3), 'baz': (22,17,12)}
figure, axes = plt.subplots(1, 3)
i = 0
for x in ['foo','bar','baz']:
    venn2(subsets = data_dict[x], set_labels=('A', 'B'), ax=axes[i])
    i += 1

我想通过每个维恩图(A+B+相交)中的数字总和来缩放每个子图的大小。我该怎么做?

我刚开始在matplotlib中画维恩图,但我认为如果你在gridspec_kw中设置宽度比例是可能的。我从字典数据中汇总数据,确定构成比,指定为比值。

from matplotlib import pyplot as plt
from matplotlib_venn import venn2

data_dict = {'foo': (10,7,5), 'bar': (2,6,3), 'baz': (22,17,12)}
ratios = [sum(v) for v in data_dict.values()]
norm = [n / sum(ratios) for n in ratios]

figure, axes = plt.subplots(1, 3, gridspec_kw=dict(width_ratios=norm))
i = 0
for x in ['foo','bar','baz']:
    venn2(subsets = data_dict[x], set_labels=('A', 'B'), ax=axes[i])
    i += 1