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..adeff3ef441b 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 %} @@ -537,17 +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 low and high res PNGs and a PDF - 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 @@ -559,14 +549,27 @@ 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))) - 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 @@ -666,6 +669,9 @@ def run(arguments, content, options, state_machine, state, lineno): config = document.settings.env.config nofigs = 'nofigs' in options + formats = get_plot_formats(config) + default_fmt = 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 +820,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