Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何关闭测试图形matplotlib_Python_Testing_Matplotlib - Fatal编程技术网

Python 如何关闭测试图形matplotlib

Python 如何关闭测试图形matplotlib,python,testing,matplotlib,Python,Testing,Matplotlib,我在一个模块中进行了一系列图像比较测试。当使用pytest时,我得到一个内存不足的警告,我假设这是由于打开了多个测试图像20+。我该如何清洗或关闭它们?由于我的代码设置,fig.close无法工作。我在下面附上了一个测试示例 @pytest.mark.mpl_image_compare(baseline_dir='baseline', filename='file.png', style=

我在一个模块中进行了一系列图像比较测试。当使用pytest时,我得到一个内存不足的警告,我假设这是由于打开了多个测试图像20+。我该如何清洗或关闭它们?由于我的代码设置,fig.close无法工作。我在下面附上了一个测试示例

@pytest.mark.mpl_image_compare(baseline_dir='baseline',
                           filename='file.png',
                           style=('style_guidline'),
                           savefig_kwargs={'bbox_inches': 'tight'},
                           tolerance=5)
def test_3(self):
    data = pd.read_csv('test.csv')
    fig = module.create_figure(
    data=data,
    kind="bar_chart",
    )
    return fig

一个万无一失的解决方案是关闭所有打开的数字:

>>> plt.close('all')
例如:

>>> import matplotlib.pyplot as plt
... 

>>> fig1, ax1 = plt.subplots()
... fig2, ax2 = plt.subplots()  # 2 separate figures
... 

>>> plt.get_fignums()
... 
[1, 2]

>>> plt.close('all')

>>> plt.get_fignums()
... 
[]
此处的其他选项: