@@ -377,7 +377,7 @@ def remove_coding(text):
377377 {% endif %}
378378
379379 {% for img in images %}
380- .. figure:: {{ build_dir }}/{{ img.basename }}.png
380+ .. figure:: {{ build_dir }}/{{ img.basename }}.{{ default_fmt }}
381381 {% for option in options -%}
382382 {{ option }}
383383 {% endfor %}
@@ -537,17 +537,7 @@ def clear_state(plot_rcparams, close=True):
537537 matplotlib .rcParams .update (plot_rcparams )
538538
539539
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 ):
551541 default_dpi = {'png' : 80 , 'hires.png' : 200 , 'pdf' : 200 }
552542 formats = []
553543 plot_formats = config .plot_formats
@@ -559,14 +549,27 @@ def render_figures(code, code_path, output_dir, output_base, context,
559549 for fmt in plot_formats :
560550 if isinstance (fmt , six .string_types ):
561551 if ':' in fmt :
562- suffix ,dpi = fmt .split (':' )
552+ suffix , dpi = fmt .split (':' )
563553 formats .append ((str (suffix ), int (dpi )))
564554 else :
565555 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 :
567557 formats .append ((str (fmt [0 ]), int (fmt [1 ])))
568558 else :
569559 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 )
570573
571574 # -- Try to determine if all images already exist
572575
@@ -666,6 +669,9 @@ def run(arguments, content, options, state_machine, state, lineno):
666669 config = document .settings .env .config
667670 nofigs = 'nofigs' in options
668671
672+ formats = get_plot_formats (config )
673+ default_fmt = formats [0 ][0 ]
674+
669675 options .setdefault ('include-source' , config .plot_include_source )
670676 keep_context = 'context' in options
671677 context_opt = None if not keep_context else options ['context' ]
@@ -814,6 +820,7 @@ def run(arguments, content, options, state_machine, state, lineno):
814820
815821 result = format_template (
816822 config .plot_template or TEMPLATE ,
823+ default_fmt = default_fmt ,
817824 dest_dir = dest_dir_link ,
818825 build_dir = build_dir_link ,
819826 source_link = src_link ,
0 commit comments