Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A pytest plugin to facilitate image comparison for Matplotlib figures

License

NotificationsYou must be signed in to change notification settings

matplotlib/pytest-mpl

Repository files navigation

pytest-mpl is apytest plugin to facilitate image comparison forMatplotlib figures.

For each figure to test, an image is generated and then subtracted from an existing reference image.If the RMS of the residual is larger than a user-specified tolerance, the test will fail.Alternatively, the generated image can be hashed and compared to an expected value.

For more information, see thepytest-mpl documentation.

Installation

pip install pytest-mpl

For detailed instructions, see theinstallation guide in thepytest-mpl docs.

Usage

First, write test functions that create a figure.These image comparison tests are decorated with@pytest.mark.mpl_image_compare and return the figure for testing:

importmatplotlib.pyplotaspltimportpytest@pytest.mark.mpl_image_comparedeftest_plot():fig,ax=plt.subplots()ax.plot([1,2])returnfig

Then, generate reference images by running the test suite with the--mpl-generate-path option:

pytest --mpl-generate-path=baseline

Then, run the test suite as usual, but pass--mpl to compare the returned figures to the reference images:

pytest --mpl

By also passing--mpl-generate-summary=html, a summary of the image comparison results will be generated in HTML format:

html allhtml filterhtml result

For more information on how to configure and usepytest-mpl, see thepytest-mpl documentation.

Contributing

pytest-mpl is a community project maintained for and by its users.There are many ways you can help!

  • Report a bug or request a featureon GitHub
  • Improve the documentation or code

About

A pytest plugin to facilitate image comparison for Matplotlib figures

Resources

License

Stars

Watchers

Forks

Contributors28


[8]ページ先頭

©2009-2025 Movatter.jp