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 b31f0ab commit 8303274
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions nutils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ def mplfigure(name, /, **kwargs):
:class:`matplotlib.figure.Figure` object.
'''

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:])


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

0 comments on commit 8303274

Please sign in to comment.