-
Notifications
You must be signed in to change notification settings - Fork 360
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
[MRG + 1] Create a new figure and test each plot type #127 #179
Conversation
- move `plot()` to `plotting.py` as `plot_pdf()` - modify plotting functions to return matplotlib figures - add `test_plotting.py` and baseline images - import `plot_pdf()` in `__init__` - update `cli.py` to use `plot_pdf()` - update advanced usage docs to reflect changes
@vinayak-mehta Any idea why changing the matplotlib backend doesn't help with the Python 2.7 build while the others pass? |
Build logs
Would moving |
Sure, you could try that. But why do you need to specify the backend in the first place? Isn't |
I don't think |
- use matplotlib rectangle instead of `cv2.rectangle` in `plot_contour()` - set matplotlib backend in `tests/__init__` - update contour plot baseline image - update `test_plotting` with more checks
Codecov Report
@@ Coverage Diff @@
## master #179 +/- ##
==========================================
+ Coverage 84.12% 87.98% +3.85%
==========================================
Files 13 13
Lines 1235 1248 +13
Branches 297 298 +1
==========================================
+ Hits 1039 1098 +59
+ Misses 151 101 -50
- Partials 45 49 +4
Continue to review full report at Codecov.
|
tests/test_plotting.py
Outdated
for t in text: | ||
xs.extend([t[0], t[2]]) | ||
ys.extend([t[1], t[3]]) | ||
assert ax.get_xlim() == (min(xs) - 10, max(xs) + 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suyash458 Why do we need additional asserts here? Doesn't pytest compare the whole image which is a sure shot way of knowing whether the images are the same or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case image comparison tests are skipped if the --mpl
option is not specified, these asserts would still work. Ultimately though, image comparison is a sure shot test.
Should the --mpl
option be added to addopts
in setup.cfg
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and in the Makefile too. After that we shouldn't need to worry about additional asserts.
[cell.lb[1], cell.rb[1]]) | ||
plt.show() | ||
return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suyash458 Are you returning fig from the plot_* functions only for those additional asserts in the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest-mpl's image comparison decorator requires the plot functions to return a matplotlib figure
- remove unnecessary asserts - update setup.cfg and makefile with `--mpl`
@suyash458 How did you generate the baseline images? Looks like there's an error of 10 units, so the tests are failing with the default tolerance of 2. |
@vinayak-mehta I'm not sure why the tests fail on Travis even though they pass locally. The baseline images were generated using the same matplotlib backend I used the |
I mean did you generate the plots using the CLI and then saved them from the matplotlib interface? or using the API. I'll try to run the tests locally too. |
|
3 looks the best to me. |
Option 3 looks like the best bet. I think the large RMS error could be because of different system fonts being used. pytest-mpl has an option to exclude text from the comparison test so I'll try that |
update plot tests with `remove_text`
Looks like the tests passed after excluding text from the baseline images. The py3.7 build failed because of an AWS timeout |
Restarted. |
Should we go ahead with this so the tests don't fail on Travis or locally owing to differences in freetype fonts? |
|
efe48da
to
c83ebc2
Compare
@suyash458 Thanks for the contribution! |
@vinayak-mehta Glad I could help! |
plot()
toplotting.py
asplot_pdf()
plot_pdf()
test_plotting.py
and baseline imagesplot_pdf()
in__init__
cli.py
to useplot_pdf()