From 43c66e16c42cf4407edc20314f4d7375047fcde5 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 14 Dec 2015 14:20:42 -0500 Subject: [PATCH 1/2] Fix #5573: Use SVG in docs --- doc/conf.py | 2 +- lib/matplotlib/sphinxext/plot_directive.py | 16 ++++++++++++---- lib/matplotlib/textpath.py | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index e336fd075253..5a68653d38bc 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -114,7 +114,7 @@ # Plot directive configuration # ---------------------------- -plot_formats = [('png', 80), ('hires.png', 200), ('pdf', 50)] +plot_formats = [('svg', 72), ('png', 80)] # Subdirectories in 'examples/' directory of package and titles for gallery mpl_example_sections = ( diff --git a/lib/matplotlib/sphinxext/plot_directive.py b/lib/matplotlib/sphinxext/plot_directive.py index f86cca7ebab1..e12a51871d63 100644 --- a/lib/matplotlib/sphinxext/plot_directive.py +++ b/lib/matplotlib/sphinxext/plot_directive.py @@ -377,7 +377,7 @@ def remove_coding(text): {% endif %} {% for img in images %} - .. figure:: {{ build_dir }}/{{ img.basename }}.png + .. figure:: {{ build_dir }}/{{ img.basename }}.{{ default_fmt }} {% for option in options -%} {{ option }} {% endfor %} @@ -541,8 +541,7 @@ def render_figures(code, code_path, output_dir, output_base, context, function_name, config, context_reset=False, close_figs=False): """ - Run a pyplot script and save the low and high res PNGs and a PDF - in *output_dir*. + Run a pyplot script and save the images in *output_dir*. Save the images under *output_dir* with file names derived from *output_base* @@ -559,7 +558,7 @@ def render_figures(code, code_path, output_dir, output_base, context, for fmt in plot_formats: if isinstance(fmt, six.string_types): if ':' in fmt: - suffix,dpi = fmt.split(':') + suffix, dpi = fmt.split(':') formats.append((str(suffix), int(dpi))) else: formats.append((fmt, default_dpi.get(fmt, 80))) @@ -666,6 +665,14 @@ def run(arguments, content, options, state_machine, state, lineno): config = document.settings.env.config nofigs = 'nofigs' in options + plot_formats = config.plot_formats + if isinstance(plot_formats, six.string_types): + # String Sphinx < 1.3, Split on , to mimic + # Sphinx 1.3 and later. Sphinx 1.3 always + # returns a list. + plot_formats = plot_formats.split(',') + default_fmt = plot_formats[0][0] + options.setdefault('include-source', config.plot_include_source) keep_context = 'context' in options context_opt = None if not keep_context else options['context'] @@ -814,6 +821,7 @@ def run(arguments, content, options, state_machine, state, lineno): result = format_template( config.plot_template or TEMPLATE, + default_fmt=default_fmt, dest_dir=dest_dir_link, build_dir=build_dir_link, source_link=src_link, diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index f9de913bfaf3..eac6568f0492 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -343,7 +343,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None, 1094995778)]: try: font.select_charmap(charmap_code) - except ValueError: + except (ValueError, RuntimeError): pass else: break From f6b15c5dd50ac97c42359bcf387699c13728a58e Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 15 Dec 2015 08:33:44 -0500 Subject: [PATCH 2/2] Fix format parsing --- lib/matplotlib/sphinxext/plot_directive.py | 35 +++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/matplotlib/sphinxext/plot_directive.py b/lib/matplotlib/sphinxext/plot_directive.py index e12a51871d63..adeff3ef441b 100644 --- a/lib/matplotlib/sphinxext/plot_directive.py +++ b/lib/matplotlib/sphinxext/plot_directive.py @@ -537,16 +537,7 @@ def clear_state(plot_rcparams, close=True): matplotlib.rcParams.update(plot_rcparams) -def render_figures(code, code_path, output_dir, output_base, context, - function_name, config, context_reset=False, - close_figs=False): - """ - Run a pyplot script and save the images in *output_dir*. - - Save the images under *output_dir* with file names derived from - *output_base* - """ - # -- Parse format list +def get_plot_formats(config): default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200} formats = [] plot_formats = config.plot_formats @@ -562,10 +553,23 @@ def render_figures(code, code_path, output_dir, output_base, context, formats.append((str(suffix), int(dpi))) else: formats.append((fmt, default_dpi.get(fmt, 80))) - elif type(fmt) in (tuple, list) and len(fmt)==2: + elif type(fmt) in (tuple, list) and len(fmt) == 2: formats.append((str(fmt[0]), int(fmt[1]))) else: raise PlotError('invalid image format "%r" in plot_formats' % fmt) + return formats + + +def render_figures(code, code_path, output_dir, output_base, context, + function_name, config, context_reset=False, + close_figs=False): + """ + Run a pyplot script and save the images in *output_dir*. + + Save the images under *output_dir* with file names derived from + *output_base* + """ + formats = get_plot_formats(config) # -- Try to determine if all images already exist @@ -665,13 +669,8 @@ def run(arguments, content, options, state_machine, state, lineno): config = document.settings.env.config nofigs = 'nofigs' in options - plot_formats = config.plot_formats - if isinstance(plot_formats, six.string_types): - # String Sphinx < 1.3, Split on , to mimic - # Sphinx 1.3 and later. Sphinx 1.3 always - # returns a list. - plot_formats = plot_formats.split(',') - default_fmt = plot_formats[0][0] + formats = get_plot_formats(config) + default_fmt = formats[0][0] options.setdefault('include-source', config.plot_include_source) keep_context = 'context' in options