问题描述
使用以下代码,我试图创建维恩图然后另存为文件.
With the following code I tried to create the Venn diagramthen saved as a file.
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')
但这给了我错误.正确的方法是什么?
But it gave me error. What's the right way to do it?
这是我在Ipython下执行的示例图:
This is the example figure where I exceuted under Ipython:
推荐答案
venn2
是一个返回 VennDiagram
实例的函数.但是,类 VennDiagram
并没有您所希望的savefig方法.您要尝试做的就是保存结果图.为此,根据加载的模块,可以使用以下命令.
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')
代替
plt.savefig('test.png')
这可能会为您解决问题.
This might solve the problem for you.
欢呼
这篇关于如何在matplotlib_venn中将VennDiagram保存为PNG图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!