|
53 | 53 | the RST document if no script is provided. The string can include the
|
54 | 54 | format ``{counter}`` to use an incremented counter. For example,
|
55 | 55 | ``'plot-{counter}'`` will create files like ``plot-1.png``, ``plot-2.png``,
|
56 |
| - and so on. If the ``{counter}`` is not provided, two plots with the same |
57 |
| - output-base-name may overwrite each other. |
| 56 | + and so on. |
58 | 57 |
|
59 | 58 | ``:format:`` : {'python', 'doctest'}
|
60 | 59 | The format of the input. If unset, the format is auto-detected.
|
|
98 | 97 | The plot directive has the following configuration options:
|
99 | 98 |
|
100 | 99 | plot_output_base_name
|
101 |
| - Default value for the output-base-name option (default is to use the name |
102 |
| - of the input script, or the name of the RST file if no script is provided) |
| 100 | + Default value for the output-base-name option. It's recommended to the |
| 101 | + format string ``{counter}`` (for example, ``'plot-{counter}'``) so that |
| 102 | + multiple plots in the same document will not conflict with each other. |
| 103 | + (default is to use the name of the input script, or the name of the RST |
| 104 | + file if no script is provided) |
103 | 105 |
|
104 | 106 | plot_include_source
|
105 | 107 | Default value for the include-source option (default: False).
|
@@ -714,13 +716,17 @@ def render_figures(code, code_path, output_dir, output_base, context,
|
714 | 716 |
|
715 | 717 | for fmt, dpi in formats:
|
716 | 718 | try:
|
| 719 | + if os.path.exists(img.filename(fmt)): |
| 720 | + raise PlotError('file %s already exists. You may need to set output-base-name to something else.' % img.filename(fmt)) |
717 | 721 | figman.canvas.figure.savefig(img.filename(fmt), dpi=dpi)
|
718 | 722 | if fmt == formats[0][0] and config.plot_srcset:
|
719 | 723 | # save a 2x, 3x etc version of the default...
|
720 | 724 | srcset = _parse_srcset(config.plot_srcset)
|
721 | 725 | for mult, suffix in srcset.items():
|
722 | 726 | fm = f'{suffix}.{fmt}'
|
723 | 727 | img.formats.append(fm)
|
| 728 | + if os.path.exists(img.filename(fm)): |
| 729 | + raise PlotError('file %s already exists. You may need to set output-base-name to something else.' % img.filename(fmt)) |
724 | 730 | figman.canvas.figure.savefig(img.filename(fm),
|
725 | 731 | dpi=int(dpi * mult))
|
726 | 732 | except Exception as err:
|
|
0 commit comments