Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6b15c5

Browse files
committed
Fix format parsing
1 parent 43c66e1 commit f6b15c5

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +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 images in *output_dir*.
545-
546-
Save the images under *output_dir* with file names derived from
547-
*output_base*
548-
"""
549-
# -- Parse format list
540+
def get_plot_formats(config):
550541
default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200}
551542
formats = []
552543
plot_formats = config.plot_formats
@@ -562,10 +553,23 @@ def render_figures(code, code_path, output_dir, output_base, context,
562553
formats.append((str(suffix), int(dpi)))
563554
else:
564555
formats.append((fmt, default_dpi.get(fmt, 80)))
565-
elif type(fmt) in (tuple, list) and len(fmt)==2:
556+
elif type(fmt) in (tuple, list) and len(fmt) == 2:
566557
formats.append((str(fmt[0]), int(fmt[1])))
567558
else:
568559
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)
569573

570574
# -- Try to determine if all images already exist
571575

@@ -665,13 +669,8 @@ def run(arguments, content, options, state_machine, state, lineno):
665669
config = document.settings.env.config
666670
nofigs = 'nofigs' in options
667671

668-
plot_formats = config.plot_formats
669-
if isinstance(plot_formats, six.string_types):
670-
# String Sphinx < 1.3, Split on , to mimic
671-
# Sphinx 1.3 and later. Sphinx 1.3 always
672-
# returns a list.
673-
plot_formats = plot_formats.split(',')
674-
default_fmt = plot_formats[0][0]
672+
formats = get_plot_formats(config)
673+
default_fmt = formats[0][0]
675674

676675
options.setdefault('include-source', config.plot_include_source)
677676
keep_context = 'context' in options

0 commit comments

Comments
 (0)