Skip to content

Commit d2eaaa6

Browse files
committed
only close all if there are any to close
avoids unnecessary gc on matplotlib < 1.4
1 parent b3dc23e commit d2eaaa6

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

backend_inline.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
"""A matplotlib backend for publishing figures via display_data"""
2-
#-----------------------------------------------------------------------------
3-
# Copyright (C) 2011 The IPython Development Team
4-
#
5-
# Distributed under the terms of the BSD License. The full license is in
6-
# the file COPYING, distributed as part of this software.
7-
#-----------------------------------------------------------------------------
8-
9-
#-----------------------------------------------------------------------------
10-
# Imports
11-
#-----------------------------------------------------------------------------
2+
3+
# Copyright (c) IPython Development Team.
4+
# Distributed under the terms of the Modified BSD License.
5+
126
from __future__ import print_function
137

14-
# Third-party imports
158
import matplotlib
169
from matplotlib.backends.backend_agg import new_figure_manager, FigureCanvasAgg # analysis: ignore
1710
from matplotlib._pylab_helpers import Gcf
1811

19-
# Local imports
2012
from IPython.core.getipython import get_ipython
2113
from IPython.core.display import display
2214

2315
from .config import InlineBackend
2416

25-
#-----------------------------------------------------------------------------
26-
# Functions
27-
#-----------------------------------------------------------------------------
2817

2918
def show(close=None):
3019
"""Show all figures as SVG/PNG payloads sent to the IPython clients.
@@ -43,7 +32,9 @@ def show(close=None):
4332
display(figure_manager.canvas.figure)
4433
finally:
4534
show._to_draw = []
46-
if close:
35+
# only call close('all') if any to close
36+
# close triggers gc.collect, which can be slow
37+
if close and Gcf.get_all_fig_managers():
4738
matplotlib.pyplot.close('all')
4839

4940

0 commit comments

Comments
 (0)