Skip to content

Commit

Permalink
simplify mplfigure
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjanvanzwieten committed Feb 9, 2024
1 parent 30af5c9 commit e84396b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions nutils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@ def mplfigure(name, /, **kwargs):
'''

with warnings.ignore(DeprecationWarning):
import matplotlib.figure
import matplotlib.backends.backend_agg
fig = matplotlib.figure.Figure(**kwargs)
from matplotlib.figure import Figure
fig = Figure(**kwargs)
with log.userfile(name, 'wb') as f:
yield fig
if f:
matplotlib.backends.backend_agg.FigureCanvas(fig) # sets reference via fig.set_canvas
try:
fig.savefig(f, format=os.path.splitext(name)[1][1:])
finally:
fig.set_canvas(None) # break circular reference
fig.savefig(f, format=os.path.splitext(name)[1][1:])
fig.clear()


def plotlines_(ax, xy, lines, **kwargs):
Expand Down

0 comments on commit e84396b

Please sign in to comment.