156
156
import matplotlib
157
157
from matplotlib .backend_bases import FigureManagerBase
158
158
import matplotlib .pyplot as plt
159
- from matplotlib import _pylab_helpers , cbook
159
+ from matplotlib import _pylab_helpers , cbook , sphinxext
160
160
161
161
matplotlib .use ("agg" )
162
162
align = cbook .deprecated (
@@ -254,6 +254,13 @@ def run(self):
254
254
raise self .error (str (e ))
255
255
256
256
257
+ def _copy_css_file (app , exc ):
258
+ if exc is None and app .builder .format == 'html' :
259
+ src = sphinxext ._static_path / Path ('plot_directive.css' )
260
+ dst = app .outdir / Path ('_static' )
261
+ shutil .copy (src , dst )
262
+
263
+
257
264
def setup (app ):
258
265
setup .app = app
259
266
setup .config = app .config
@@ -269,9 +276,9 @@ def setup(app):
269
276
app .add_config_value ('plot_apply_rcparams' , False , True )
270
277
app .add_config_value ('plot_working_directory' , None , True )
271
278
app .add_config_value ('plot_template' , None , True )
272
-
273
279
app .connect ('doctree-read' , mark_plot_labels )
274
-
280
+ app .add_css_file ('plot_directive.css' )
281
+ app .connect ('build-finished' , _copy_css_file )
275
282
metadata = {'parallel_read_safe' : True , 'parallel_write_safe' : True ,
276
283
'version' : matplotlib .__version__ }
277
284
return metadata
@@ -521,7 +528,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
521
528
"""
522
529
formats = get_plot_formats (config )
523
530
524
- # -- Try to determine if all images already exist
531
+ # Try to determine if all images already exist
525
532
526
533
code_pieces = split_code_at_show (code )
527
534
@@ -624,6 +631,10 @@ def run(arguments, content, options, state_machine, state, lineno):
624
631
default_fmt = formats [0 ][0 ]
625
632
626
633
options .setdefault ('include-source' , config .plot_include_source )
634
+ if 'class' in options :
635
+ options ['class' ] = options ['class' ] + ' plot-directive'
636
+ else :
637
+ options .setdefault ('class' , 'plot-directive' )
627
638
keep_context = 'context' in options
628
639
context_opt = None if not keep_context else options ['context' ]
629
640
0 commit comments