Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9459e42
Update testing.rst
SunSummoner Aug 15, 2023
e6229e2
Merge pull request #1 from SunSummoner/SunSummoner-patch-1
SunSummoner Aug 15, 2023
1c28caa
Update testing.rst
SunSummoner Aug 16, 2023
4df929f
Merge branch 'matplotlib:main' into main
SunSummoner Aug 16, 2023
0ff2125
Update doc/devel/testing.rst
SunSummoner Aug 16, 2023
a182f3f
Update testing.rst
SunSummoner Aug 17, 2023
f1726fc
Update testing.rst
SunSummoner Aug 17, 2023
4edea20
Update testing.rst
SunSummoner Aug 17, 2023
302aa4e
Update doc/devel/testing.rst
SunSummoner Aug 17, 2023
bb3a00e
Update testing.rst
SunSummoner Aug 17, 2023
30bb251
Merge branch 'matplotlib:main' into main
SunSummoner Aug 18, 2023
6d2e74f
Resolving pre-commit-hook changes
SunSummoner Aug 18, 2023
1b74005
Merge branch 'matplotlib:main' into main
SunSummoner Aug 18, 2023
412f8c3
Update doc/devel/testing.rst
SunSummoner Aug 19, 2023
132b13d
Resolving pre-commit-hook changes
SunSummoner Aug 19, 2023
9d5ea74
Merge branch 'main' of https://github.com/SunSummoner/matplotlib
SunSummoner Aug 19, 2023
744e6d4
Resolving pre-commit-hook changes
SunSummoner Aug 22, 2023
175ebd8
Merge branch 'matplotlib:main' into main
SunSummoner Aug 22, 2023
461494e
Update testing.rst
SunSummoner Aug 22, 2023
4add791
Update testing.rst
SunSummoner Aug 22, 2023
02203f1
Update testing.rst
SunSummoner Aug 22, 2023
4d7c58f
Update testing.rst
SunSummoner Aug 22, 2023
323fd7b
Update testing.rst
SunSummoner Aug 22, 2023
8e51433
Update testing.rst
SunSummoner Aug 22, 2023
30251e3
Update doc/devel/testing.rst
SunSummoner Aug 23, 2023
3d74be9
Update doc/devel/testing.rst
SunSummoner Aug 23, 2023
1e94e0c
Merge branch 'matplotlib:main' into main
SunSummoner Aug 27, 2023
c386d8e
accidental new line
story645 Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions doc/devel/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ tests it::

from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt

Comment thread
SunSummoner marked this conversation as resolved.
Outdated
@image_comparison(baseline_images=['line_dashes'], remove_text=True,
extensions=['png'], style='mpl20')
def test_line_dashes():
Expand All @@ -122,19 +122,34 @@ case :file:`lib/matplotlib/tests/baseline_images/test_lines`). Put this new
file under source code revision control (with ``git add``). When rerunning
the tests, they should now pass.

It is preferred that new tests use ``style='mpl20'`` as this leads to smaller
figures and reflects the newer look of default Matplotlib plots. Also, if the
texts (labels, tick labels, etc) are not really part of what is tested, use
``remove_text=True`` as this will lead to smaller figures and reduce possible
issues with font mismatch on different platforms.

Baseline images take a lot of space in the Matplotlib repository.
An alternative approach for image comparison tests is to use the
`~matplotlib.testing.decorators.check_figures_equal` decorator, which should be
used to decorate a function taking two `.Figure` parameters and draws the same
images on the figures using two different methods (the tested method and the
baseline method). The decorator will arrange for setting up the figures and
then collect the drawn results and compare them.

It is preferred that new tests use ``style='mpl20'`` as this leads to smaller
figures and reflects the newer look of default Matplotlib plots. Also, if the
texts (labels, tick labels, etc) are not really part of what is tested, use
``remove_text=True`` as this will lead to smaller figures and reduce possible
issues with font mismatch on different platforms.
then collect the drawn results and compare them. For example, this test draws
the same circle on the figures with two different methods::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe me more explicit about the two methods (drawing via adding circle patch vs drawing via plotting a circle)? And change the name of the test method to whichever method you're testing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate the second part? I am not quite sure what you mean. Do you mean change the name of the test method in the code?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean change the name of the test method in the code?

Exactly! Something like test_parametric_circle_plot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! I'll edit it.


from matplotlib.testing.decorators import check_figures_equal
import matplotlib.pyplot as plt

@check_figures_equal(extensions=['png'], tol=100)
def test_plot(fig_test, fig_ref):
red_circle = plt.Circle((0, 0), 0.2, color='r', clip_on=False)
fig_ref.add_artist(red_circle)
fig_ref.subplots().plot([0,1,2], [3,4,5], color='red')
Comment thread
SunSummoner marked this conversation as resolved.
Outdated

In this example, one of the argument is ``tol=100`` where tol is used for the
determining the tolerance (a color value difference, where 255 is the maximal
difference). The test fails if the average pixel difference is greater than
this value.

See the documentation of `~matplotlib.testing.decorators.image_comparison` and
`~matplotlib.testing.decorators.check_figures_equal` for additional information
Expand Down