@@ -90,7 +90,6 @@ When generating a hash library, the tests will also be run as usual against the
9090existing hash library specified by ``--mpl-hash-library `` or the keyword argument.
9191However, generating baseline images will always result in the tests being skipped.
9292
93-
9493Hybrid Mode: Hashes and Images
9594^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9695
@@ -278,6 +277,62 @@ decorator:
278277 This will make the test insensitive to changes in e.g. the freetype
279278library.
280279
280+ Supported formats and deterministic output
281+ ------------------------------------------
282+
283+ By default, pytest-mpl will save and compare figures in PNG format. However,
284+ it is possible to set the format to use by setting e.g. ``savefig_kwargs={'format': 'pdf'} ``
285+ in ``mpl_image_compare ``. Supported formats are ``'eps' ``, ``'pdf' ``, ``'png' ``, and ``'svg' ``.
286+ Note that Ghostscript is required to be installed for comparing PDF and EPS figures, while
287+ Inkscape is required for SVG comparison.
288+
289+ By default, Matplotlib does not produce deterministic output that will
290+ have a consistent hash every time it is run, or over different Matplotlib versions.
291+ In order to enforce that the output is deterministic, you will need to do the following:
292+
293+ PNG
294+ ^^^
295+
296+ For PNG files, the output can be made deterministic by setting::
297+
298+ @pytest.mark.mpl_image_compare(savefig_kwargs={'metadata': {"Software": None}})
299+
300+ PDF
301+ ^^^
302+
303+ For PDF files, the output can be made deterministic by setting::
304+
305+ @pytest.mark.mpl_image_compare(savefig_kwargs={'format': 'pdf',
306+ 'metadata': {"Creator": None,
307+ "Producer": None,
308+ "CreationDate": None}})
309+
310+ EPS
311+ ^^^
312+
313+ For PDF files, the output can be made deterministic by setting::
314+
315+ @pytest.mark.mpl_image_compare(savefig_kwargs={'format': 'pdf',
316+ 'metadata': {"Creator": "test"})
317+
318+ and in addition you will need to set the SOURCE_DATE_EPOCH environment variable to
319+ a constant value (this is a unit timestamp)::
320+
321+ os.environ['SOURCE_DATE_EPOCH'] = '1680254601'
322+
323+ You could do this inside the test.
324+
325+ SVG
326+ ^^^
327+
328+ For SVG files, the output can be made deterministic by setting::
329+
330+ @pytest.mark.mpl_image_compare(savefig_kwargs={'metadata': '{"Date": None}})
331+
332+ and in addition, you should make sure the following rcParam is set to a constant string::
333+
334+ plt.rcParams['svg.hashsalt'] = 'test'
335+
281336Test failure example
282337--------------------
283338
0 commit comments