@@ -288,69 +288,15 @@ Inkscape is required for SVG comparison.
288288
289289By default, Matplotlib does not produce deterministic output that will have a
290290consistent hash every time it is run, or over different Matplotlib versions. In
291- order to enforce that the output is deterministic, you will need to set metadata
292- as described in the following subsections.
293-
294- PNG
295- ^^^
296-
297- For PNG files, the output can be made deterministic by setting:
298-
299- .. code :: python
300-
301- @pytest.mark.mpl_image_compare (savefig_kwargs = {' metadata' : {" Software" : None }})
302-
303- PDF
304- ^^^
305-
306- For PDF files, the output can be made deterministic by setting:
307-
308- .. code :: python
309-
310- @pytest.mark.mpl_image_compare (savefig_kwargs = {' format' : ' pdf' ,
311- ' metadata' : {" Creator" : None ,
312- " Producer" : None ,
313- " CreationDate" : None }})
314-
315- Note that deterministic PDF output can only be achieved with Matplotlib 2.1 and above
316-
317- EPS
318- ^^^
319-
320- For PDF files, the output can be made deterministic by setting:
321-
322- .. code :: python
323-
324- @pytest.mark.mpl_image_compare (savefig_kwargs = {' format' : ' pdf' ,
325- ' metadata' : {" Creator" : " test" })
326-
327- and in addition you will need to set the SOURCE_DATE_EPOCH environment variable to
328- a constant value (this is a unit timestamp):
329-
330- .. code:: python
331-
332- os.environ[' SOURCE_DATE_EPOCH' ] = ' 1680254601'
333-
334- You could do this inside the test.
335-
336- Note that deterministic PDF output can only be achieved with Matplotlib 2.1 and above
337-
338- SVG
339- ^^^
340-
341- For SVG files, the output can be made deterministic by setting:
342-
343- .. code:: python
344-
345- @ pytest.mark.mpl_image_compare(savefig_kwargs = {' metadata' : ' {"Date": None}} )
346-
347- and in addition, you should make sure the following rcParam is set to a constant string:
291+ order to enforce that the output is deterministic, you can set the ``deterministic ``
292+ keyword argument in ``mpl_image_compare ``:
348293
349294.. code :: python
350295
351- plt.rcParams[ ' svg.hashsalt ' ] = ' test '
296+ @pytest.mark.mpl_image_compare ( deterministic = True )
352297
353- Note that SVG files can only be used in pytest- mpl with Matplotlib 3.3 and above.
298+ This does a number of things such as e.g., setting the creation date in the
299+ metadata to be constant, and avoids hard-coding the Matplotlib in the files.
354300
355301Test failure example
356302--------------------
0 commit comments