-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Resolves #26421 Added an example for fig comparison decorator #26538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
9459e42
e6229e2
1c28caa
4df929f
0ff2125
a182f3f
f1726fc
4edea20
302aa4e
bb3a00e
30bb251
6d2e74f
1b74005
412f8c3
132b13d
9d5ea74
744e6d4
175ebd8
461494e
4add791
02203f1
4d7c58f
323fd7b
8e51433
30251e3
3d74be9
1e94e0c
c386d8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ tests it:: | |
|
|
||
| from matplotlib.testing.decorators import image_comparison | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| @image_comparison(baseline_images=['line_dashes'], remove_text=True, | ||
| extensions=['png'], style='mpl20') | ||
| def test_line_dashes(): | ||
|
|
@@ -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:: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly! Something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.