matplotlib / matplotlib/pytest-mpl

Margins removed in baseline

Open
#49 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
272
Forks
53
PR merge metrics
No merged PRs in 30d

Description

When I run or save a modified README code in Jupyter, I get a different image than the generated baseline.

Example code run in a Jupyter cell:

#%%file test.py
%matplotlib inline

import matplotlib.pyplot as plt
import pytest

@pytest.mark.mpl_image_compare
def test_succeeds():
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    ax.plot([1,2,3])
    fig.savefig("test")
    return fig

Running test_succeeds(); in Jupyter gives resulting image and saved test.png with margins:

test

Next, I generate a test.py file by uncommenting the first line, commenting the second line
and then running the cell

%%file test.py
#%matplotlib inline

...

From a command prompt, in the appropriate directory I run the following to generate the baseline image:

> py.test --mpl-generate-path=baseline test.py

In the baseline folder, a comparable image called test_succeeds.png is created without margins:

test_succeeds

Aside from the difference in sizes, I notice the baseline image uses the classic mpl style. Perhaps this is the cause for the absence in margins. I report this as an issue as it is ideal that when testing the baseline image, it should be the same image as shown and saved by Jupyter.

2017-04-18 16_25_19-scratchpad 5

I tested this with Anaconda 4.2.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the discrepancy using the Jupyter cell and the py.test --mpl-generate-path=baseline test.py command shown in the report, comparing the saved and baseline images. Trace how pytest-mpl generates baselines and how Jupyter applies Matplotlib settings; done means equivalent figures have consistent margins and style in both workflows.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter, matplotlib, python
Domain
data-visualization, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.