@@ -377,7 +377,7 @@ def remove_coding(text):
377
377
{% endif %}
378
378
379
379
{% for img in images %}
380
- .. figure:: {{ build_dir }}/{{ img.basename }}.png
380
+ .. figure:: {{ build_dir }}/{{ img.basename }}.{{ default_fmt }}
381
381
{% for option in options -%}
382
382
{{ option }}
383
383
{% endfor %}
@@ -537,17 +537,7 @@ def clear_state(plot_rcparams, close=True):
537
537
matplotlib .rcParams .update (plot_rcparams )
538
538
539
539
540
- def render_figures (code , code_path , output_dir , output_base , context ,
541
- function_name , config , context_reset = False ,
542
- close_figs = False ):
543
- """
544
- Run a pyplot script and save the low and high res PNGs and a PDF
545
- in *output_dir*.
546
-
547
- Save the images under *output_dir* with file names derived from
548
- *output_base*
549
- """
550
- # -- Parse format list
540
+ def get_plot_formats (config ):
551
541
default_dpi = {'png' : 80 , 'hires.png' : 200 , 'pdf' : 200 }
552
542
formats = []
553
543
plot_formats = config .plot_formats
@@ -559,14 +549,27 @@ def render_figures(code, code_path, output_dir, output_base, context,
559
549
for fmt in plot_formats :
560
550
if isinstance (fmt , six .string_types ):
561
551
if ':' in fmt :
562
- suffix ,dpi = fmt .split (':' )
552
+ suffix , dpi = fmt .split (':' )
563
553
formats .append ((str (suffix ), int (dpi )))
564
554
else :
565
555
formats .append ((fmt , default_dpi .get (fmt , 80 )))
566
- elif type (fmt ) in (tuple , list ) and len (fmt )== 2 :
556
+ elif type (fmt ) in (tuple , list ) and len (fmt ) == 2 :
567
557
formats .append ((str (fmt [0 ]), int (fmt [1 ])))
568
558
else :
569
559
raise PlotError ('invalid image format "%r" in plot_formats' % fmt )
560
+ return formats
561
+
562
+
563
+ def render_figures (code , code_path , output_dir , output_base , context ,
564
+ function_name , config , context_reset = False ,
565
+ close_figs = False ):
566
+ """
567
+ Run a pyplot script and save the images in *output_dir*.
568
+
569
+ Save the images under *output_dir* with file names derived from
570
+ *output_base*
571
+ """
572
+ formats = get_plot_formats (config )
570
573
571
574
# -- Try to determine if all images already exist
572
575
@@ -666,6 +669,9 @@ def run(arguments, content, options, state_machine, state, lineno):
666
669
config = document .settings .env .config
667
670
nofigs = 'nofigs' in options
668
671
672
+ formats = get_plot_formats (config )
673
+ default_fmt = formats [0 ][0 ]
674
+
669
675
options .setdefault ('include-source' , config .plot_include_source )
670
676
keep_context = 'context' in options
671
677
context_opt = None if not keep_context else options ['context' ]
@@ -814,6 +820,7 @@ def run(arguments, content, options, state_machine, state, lineno):
814
820
815
821
result = format_template (
816
822
config .plot_template or TEMPLATE ,
823
+ default_fmt = default_fmt ,
817
824
dest_dir = dest_dir_link ,
818
825
build_dir = build_dir_link ,
819
826
source_link = src_link ,
0 commit comments