105
105
A dictionary containing any non-standard rcParams that should
106
106
be applied before each plot.
107
107
108
+ plot_apply_rcparams
109
+ By default, rcParams are applied when `context` option is not used in
110
+ a plot directive. This configuration option overrides this behaviour
111
+ and applies rcParams before each plot.
112
+
113
+ plot_working_directory
114
+ By default, the working directory will be changed to the directory of
115
+ the example, so the code can get at its data files, if any. Also its
116
+ path will be added to `sys.path` so it can import any helper modules
117
+ sitting beside it. This configuration option can be used to specify
118
+ a central directory (also added to `sys.path`) where data files and
119
+ helper modules for all code are located.
120
+
121
+ plot_template
122
+ Provide a customized template for preparing resturctured text.
123
+
124
+
108
125
"""
109
126
from __future__ import print_function
110
127
@@ -284,6 +301,9 @@ def setup(app):
284
301
app .add_config_value ('plot_basedir' , None , True )
285
302
app .add_config_value ('plot_html_show_formats' , True , True )
286
303
app .add_config_value ('plot_rcparams' , {}, True )
304
+ app .add_config_value ('plot_apply_rcparams' , False , True )
305
+ app .add_config_value ('plot_working_directory' , None , True )
306
+ app .add_config_value ('plot_template' , None , True )
287
307
288
308
app .connect ('doctree-read' , mark_plot_labels )
289
309
@@ -445,7 +465,19 @@ def run_code(code, code_path, ns=None, function_name=None):
445
465
446
466
pwd = os .getcwd ()
447
467
old_sys_path = list (sys .path )
448
- if code_path is not None :
468
+ if setup .config .plot_working_directory is not None :
469
+ try :
470
+ os .chdir (setup .config .plot_working_directory )
471
+ except OSError as err :
472
+ raise OSError (str (err ) + '\n `plot_working_directory` option in'
473
+ 'Sphinx configuration file must be a valid '
474
+ 'directory path' )
475
+ except TypeError as err :
476
+ raise TypeError (str (err ) + '\n `plot_working_directory` option in '
477
+ 'Sphinx configuration file must be a string or '
478
+ 'None' )
479
+ sys .path .insert (0 , setup .config .plot_working_directory )
480
+ elif code_path is not None :
449
481
dirname = os .path .abspath (os .path .dirname (code_path ))
450
482
os .chdir (dirname )
451
483
sys .path .insert (0 , dirname )
@@ -564,7 +596,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
564
596
ns = {}
565
597
566
598
for i , code_piece in enumerate (code_pieces ):
567
- if not context :
599
+ if not context or config . plot_apply_rcparams :
568
600
clear_state (config .plot_rcparams )
569
601
run_code (code_piece , code_path , ns , function_name )
570
602
@@ -588,7 +620,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
588
620
589
621
results .append ((code_piece , images ))
590
622
591
- if not context :
623
+ if not context or config . plot_apply_rcparams :
592
624
clear_state (config .plot_rcparams )
593
625
594
626
return results
@@ -733,7 +765,7 @@ def run(arguments, content, options, state_machine, state, lineno):
733
765
src_link = None
734
766
735
767
result = format_template (
736
- TEMPLATE ,
768
+ config . plot_template or TEMPLATE ,
737
769
dest_dir = dest_dir_link ,
738
770
build_dir = build_dir_link ,
739
771
source_link = src_link ,
0 commit comments