Skip to content

Commit

Permalink
fix: close pyplot
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Jul 15, 2024
1 parent 6db1f58 commit 548cd1b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/funix/decorator/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ def get_figure(figure) -> dict:
Exception: If matplotlib or mpld3 is not installed
"""
global mpld3
import matplotlib

if __matplotlib_use:
if mpld3 is None:
try:
Expand All @@ -376,6 +378,7 @@ def get_figure(figure) -> dict:
raise Exception("if you use matplotlib, you must install mpld3")

fig = mpld3.fig_to_dict(figure)
matplotlib.pyplot.close()
return fig
else:
raise Exception("Install matplotlib to use this function")
Expand All @@ -391,6 +394,10 @@ def get_figure_image(figure) -> str:
Returns:
str: The converted image with static URI
"""
import matplotlib.pyplot

matplotlib.pyplot.close()

with io.BytesIO() as buf:
figure.savefig(buf, format="png")
buf.seek(0)
Expand Down

0 comments on commit 548cd1b

Please sign in to comment.