Skip to content

Commit 61a4926

Browse files
authored
Merge pull request #16 from pathsim/fix/baked-plots-missing
Fix baked plots missing in deployed notebooks
2 parents f7b22f8 + aa697aa commit 61a4926

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

scripts/lib/executor.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,25 @@
2020

2121

2222
# Setup code to configure matplotlib for SVG output
23-
# This is prepended to notebooks before execution
23+
# This is prepended to notebooks before execution.
24+
#
25+
# Do NOT call matplotlib.use('Agg') here: that activates the bare Agg backend,
26+
# which is non-interactive and bypasses IPython's inline display hooks. plt.show()
27+
# becomes a no-op and nbconvert never sees any image, so cell outputs end up with
28+
# stdout/stderr but figures: []. We need the matplotlib_inline backend (Agg under
29+
# the hood, plus _repr_*_ hooks that emit display_data) — activate it via the
30+
# %matplotlib inline magic before setting figure_formats to SVG.
2431
MATPLOTLIB_SVG_SETUP = '''
25-
import matplotlib
26-
matplotlib.use('Agg')
27-
import matplotlib.pyplot as plt
32+
from IPython import get_ipython
33+
ipython = get_ipython()
34+
if ipython is not None:
35+
ipython.run_line_magic('matplotlib', 'inline')
36+
ipython.run_line_magic('config', "InlineBackend.figure_formats = ['svg']")
2837
29-
# Configure matplotlib for SVG output
30-
plt.rcParams['savefig.format'] = 'svg'
38+
import matplotlib.pyplot as plt
3139
plt.rcParams['figure.facecolor'] = 'none'
3240
plt.rcParams['savefig.facecolor'] = 'none'
3341
plt.rcParams['savefig.transparent'] = True
34-
35-
# Configure IPython inline backend for SVG
36-
try:
37-
from IPython import get_ipython
38-
ipython = get_ipython()
39-
if ipython is not None:
40-
ipython.run_line_magic('config', "InlineBackend.figure_formats = ['svg']")
41-
except:
42-
pass
4342
'''
4443

4544

0 commit comments

Comments
 (0)