我想创建一个带有子图的图形,其中每个子图的大小与它包含的数据成比例。例如:
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+intersect)中的数字之和来缩放每个子图的大小。我该怎么做呢?
发布于 2021-08-03 01:52:05
我刚开始在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
https://stackoverflow.com/questions/68633192
复制相似问题