Skip to content

Commit 23beb94

Browse files
committed
Set matplotlib backend from config in pyscript
1 parent f7b463d commit 23beb94

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

nipype/pipeline/plugins/base.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ def report_nodes_not_run(notrun):
9191
'Check log for details'))
9292

9393

94-
def write_matplotlibrc(batch_dir):
95-
"""Set the matplotlib backend in a local rc file."""
96-
backend = nipype.config.get("execution", "matplotlib_backend")
97-
with open(os.path.join(batch_dir, "matplotlibrc"), "w") as fid:
98-
fid.write("backend : %s" % backend)
99-
100-
10194
def create_pyscript(node, updatehash=False, store_exception=True):
10295
# pickle node
10396
timestamp = strftime('%Y%m%d_%H%M%S')
@@ -111,12 +104,14 @@ def create_pyscript(node, updatehash=False, store_exception=True):
111104
batch_dir = os.path.join(node.base_dir, 'batch')
112105
if not os.path.exists(batch_dir):
113106
os.makedirs(batch_dir)
114-
write_matplotlibrc(batch_dir)
115107
pkl_file = os.path.join(batch_dir, 'node_%s.pklz' % suffix)
116108
savepkl(pkl_file, dict(node=node, updatehash=updatehash))
109+
mpl_backend = nipype.config.get("execution", "matplotlib_backend")
117110
# create python script to load and trap exception
118111
cmdstr = """import os
119112
import sys
113+
import matplotlib
114+
matplotlib.use('%s')
120115
from nipype import config, logging
121116
from nipype.utils.filemanip import loadpkl, savepkl
122117
from socket import gethostname
@@ -162,7 +157,7 @@ def create_pyscript(node, updatehash=False, store_exception=True):
162157
report_crash(info['node'], traceback, gethostname())
163158
raise Exception(e)
164159
"""
165-
cmdstr = cmdstr % (pkl_file, batch_dir, node.config, suffix)
160+
cmdstr = cmdstr % (mpl_backend, pkl_file, batch_dir, node.config, suffix)
166161
pyscript = os.path.join(batch_dir, 'pyscript_%s.py' % suffix)
167162
fp = open(pyscript, 'wt')
168163
fp.writelines(cmdstr)

0 commit comments

Comments
 (0)