Skip to content

Commit fc6090e

Browse files
committed
Fix leaking matplotlib figure (#2771)
Summary: In StreamWriter basic usage tutorial, matplotlib is used to generate raster images of waveforms, and the figure used is left unshown in the resulting tutorial with the use of ``sphinx_gallery_defer_figures`` command. It turned out that this figure is shown in the next code block executed by Sphinx Gallery, and the figure is placed in totally unrelated place. https://pytorch.org/audio/main/tutorials/audio_feature_extractions_tutorial.html <img width="951" alt="Screen Shot 2022-10-14 at 10 06 58 PM" src="https://user-images.githubusercontent.com/855818/195855124-ecd9be49-5085-4acd-9a93-608d9d1ee9ce.png"> This commit fixes it by closing the figure. Pull Request resolved: #2771 Reviewed By: nateanl Differential Revision: D40382076 Pulled By: mthrok fbshipit-source-id: 015f2bab8492d3b4fbe70e1174c7776a5aa2679a
1 parent 55c695b commit fc6090e

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

examples/tutorials/streamwriter_basic_tutorial.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def _plot(data):
654654
s.write_video_chunk(1, torch.stack(frames))
655655
i += frame_rate
656656

657-
# sphinx_gallery_defer_figures
657+
plt.close(fig)
658658

659659
######################################################################
660660
#
@@ -667,8 +667,6 @@ def _plot(data):
667667

668668
Video(get_path("example.mp4"), embed=True)
669669

670-
# sphinx_gallery_defer_figures
671-
672670
######################################################################
673671
#
674672
# Carefully watching the video, it can be

0 commit comments

Comments
 (0)