5

使用以下代码,我尝试创建维恩图,然后保存为文件。

import matplotlib
from matplotlib_venn import venn2
set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
plt = venn2([set1,set2],('Set1','Set2'))
plt.savefig('test.png')

但这给了我错误。正确的方法是什么?

这是我在 Ipython 下执行的示例图: 在此处输入图像描述

4

1 回答 1

7

venn2 is a function that returns an instance of VennDiagram. However, the class VennDiagram does not have the method savefig as you wish. What you are trying to do is to save the resulting figure. For that, based on your loaded modules, you can use the following command.

matplotlib.pyplot.savefig('test.png')

instead of

plt.savefig('test.png')

This might solve the problem for you.

Cheers

enter image description here

于 2015-01-29T05:20:18.520 回答