Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion matplotlib_inline/backend_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def show(close=None, block=None):
# only call close('all') if any to close
# close triggers gc.collect, which can be slow
if close and Gcf.get_all_fig_managers():
matplotlib.pyplot.close("all")
from matplotlib import pyplot

pyplot.close("all")


# This flag will be reset by draw_if_interactive when called
Expand Down
14 changes: 14 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@ def test_import():
from matplotlib_inline.backend_inline import show

show()


def test_show_closes_figures_without_pyplot_attribute(monkeypatch):
# gh-24: lazy loaders (e.g. librosa < 0.10.1) can leave matplotlib.pyplot
# in sys.modules without setting it as an attribute of matplotlib.
import matplotlib
import matplotlib.pyplot as plt

from matplotlib_inline.backend_inline import show

plt.figure()
monkeypatch.delattr(matplotlib, "pyplot")
show(close=True)
assert plt.get_fignums() == []