ensure the backend is always restored
@@ -214,6 +214,7 @@ def qsave(layout: 'Layout', filename: str, *,
# other than the main thread
old_backend = matplotlib.get_backend()
matplotlib.use('Agg')
+ try:
fig: plt.Figure = plt.figure()
ax: plt.Axes = fig.add_axes((0, 0, 1, 1))
ctx = RenderContext(layout.doc)
@@ -225,5 +226,6 @@ def qsave(layout: 'Layout', filename: str, *,
fig.savefig(filename, dpi=dpi,
facecolor=ax.get_facecolor(), transparent=True)
plt.close(fig)
+ finally:
matplotlib.use(old_backend)
