Skip to content

Fixed incorrect colour in ErrorBar when Nan value is presented #16724

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

Merged
merged 5 commits into from
Mar 22, 2020

Conversation

henryhu123
Copy link
Contributor

PR Summary

Fixed incorrect colour in ErrorBar when Nan value is presented
See #13799
Co-author : Dennis Tismenko Dennis.Tismenko@mail.utoronto.ca

After analyzing the codebase, the inconsistency issue was traced to the difference between the handling of NaN values in Axes.scatter versus Axes.hlines/Axes.vlines. In the latter case, NaN values were being deleted from their respective np.array, whereas in the former case, NaN values were handled by using a np.ma.array (masked array), where the NaN values were simply masked.

Removed cbook.delete_masked_points() when passing X and Y to Errorbar.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@tacaswell tacaswell added this to the v3.3.0 milestone Mar 11, 2020
@tacaswell
Copy link
Member

Overall this seems like the correct fix 👍

I am a bit concerned about the images that changed but look identical. Are there very small changes in them?

For the tests would it be possible to use check_figures_equal instead of adding new images?

See https://matplotlib.org/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal and https://matplotlib.org/devel/testing.html#writing-an-image-comparison-test

@tacaswell
Copy link
Member

Could you please also simplify / sqaush the git history?

@tacaswell tacaswell self-assigned this Mar 11, 2020
@henryhu123
Copy link
Contributor Author

Overall this seems like the correct fix 👍

I am a bit concerned about the images that changed but look identical. Are there very small changes in them?

For the tests would it be possible to use check_figures_equal instead of adding new images?

See https://matplotlib.org/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal and https://matplotlib.org/devel/testing.html#writing-an-image-comparison-test

@henryhu123 henryhu123 closed this Mar 11, 2020
@henryhu123 henryhu123 reopened this Mar 11, 2020
@henryhu123
Copy link
Contributor Author

Overall this seems like the correct fix 👍

I am a bit concerned about the images that changed but look identical. Are there very small changes in them?

For the tests would it be possible to use check_figures_equal instead of adding new images?

See https://matplotlib.org/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal and https://matplotlib.org/devel/testing.html#writing-an-image-comparison-test

Sorry accidentally closed the PR. Actually I didn't modify the images for hlines_basics, hlines_with_nan, hlines_masked, vlines_basics, vlines_with_nan, vlines_masked. Not sure why GitHub shows it is modified, I will look into at this issue. Thank you for your feedback.

@henryhu123
Copy link
Contributor Author

Overall this seems like the correct fix 👍
I am a bit concerned about the images that changed but look identical. Are there very small changes in them?
For the tests would it be possible to use check_figures_equal instead of adding new images?
See https://matplotlib.org/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal and https://matplotlib.org/devel/testing.html#writing-an-image-comparison-test

Sorry accidentally closed the PR. Actually I didn't modify the images for hlines_basics, hlines_with_nan, hlines_masked, vlines_basics, vlines_with_nan, vlines_masked. Not sure why GitHub shows it is modified, I will look into at this issue. Thank you for your feedback.

Re-uploaded the original test images, test images are not changed now. Can we do the squash merge?

@DennisTismenko
Copy link
Contributor

@henryhu123 I squashed the git history, so I don't think there's a need for a squash merge.

Included changes to the tests to use check_figures_equal instead of image comparison, thank you for the good suggestion.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Please give your commits meaningful message; #13799 is meaningless in a git log.

Combine array masks rather than deleting masked points to maintain
consistency across the project.

Add appropriate test cases for validating color correctness for hlines
and vlines.

Fixes issue matplotlib#13799.
@DennisTismenko
Copy link
Contributor

@QuLogic Thank you for your feedback, I implemented both the changes to the commit message and the code wrapping. We also implemented your suggestions for the tests and fixed the incorrect method calls.

@QuLogic
Copy link
Member

QuLogic commented Mar 13, 2020

I think you might have misunderstood what parametrization is for, and using cycler, while cool, is a bit overkill here. Almost all of your cyclers are 1 element except one that is 2, so their product is 2 long. It seems less work just to write out those 2 differing things.

The point of parametrizing is to remove duplication. Most of that code should still be in the test, and only the changing things need to be parametrized. Certainly the expected data is fixed and there's no need to obfuscate it by putting it in a parameter. I was thinking more that you should parametrize over vlines/hlines originally, though parametrizing over the two test cases is also a good idea.

@henryhu123
Copy link
Contributor Author

I think you might have misunderstood what parametrization is for, and using cycler, while cool, is a bit overkill here. Almost all of your cyclers are 1 element except one that is 2, so their product is 2 long. It seems less work just to write out those 2 differing things.

The point of parametrizing is to remove duplication. Most of that code should still be in the test, and only the changing things need to be parametrized. Certainly the expected data is fixed and there's no need to obfuscate it by putting it in a parameter. I was thinking more that you should parametrize over vlines/hlines originally, though parametrizing over the two test cases is also a good idea.

I have removed cycler and moved expected data to test cases. Not sure if I understand your last sentence correctly, I removed duplicated code as much as possible, and created one parametrizing generator function for both hlines/vlines test cases.

@henryhu123 henryhu123 requested a review from QuLogic March 13, 2020 23:02

@pytest.mark.parametrize('kwargs', generate_lines_with_colors_inputs())
@check_figures_equal(extensions=["png"])
def test_vlines_with_colors(fig_test, fig_ref, kwargs):
Copy link
Member

@timhoffm timhoffm Mar 19, 2020

Choose a reason for hiding this comment

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

You can greatily simplify the tests:

  • The only variable part is the data. All other parameters are identical. You can just hard-code them. No need to build dicts and pass them as kwargs.
  • ymin/ymax can be scalars.
  • You can test hlines and vlines within one figure:
    image
  • Optionally / alternatively, you can make 2 or 4 subplots and draw the different cases into different axes on the same figure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Removed passing kwargs, hard-code the identical values.
  • ymin/ymax are scalars now
  • hlines and vlines is in one figure with 2 subplots now.

@henryhu123 henryhu123 requested a review from timhoffm March 19, 2020 17:54
ymin = np.ma.resize(ymin, x.shape)
ymax = np.ma.resize(ymax, x.shape)

masked_verts = [np.ma.array([xymin, xymax])
Copy link
Member

Choose a reason for hiding this comment

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

Simpler and faster:

        masked_verts = np.ma.empty((len(x), 2, 2))
        masked_verts[:, 0, 0] = x
        masked_verts[:, 1, 0] = x
        masked_verts[:, 0, 1] = ymin
        masked_verts[:, 1, 1] = ymax

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is definitely cleaner than what I had before, thank you for the suggestion! Pushed.

@henryhu123 henryhu123 requested a review from timhoffm March 20, 2020 23:20
@henryhu123
Copy link
Contributor Author

@timhoffm Hi, do you have any idea why Travis CI MacOs build test failed, I have looked through error information and have no idea how to fix it.

@QuLogic
Copy link
Member

QuLogic commented Mar 22, 2020

This is a known issue #16849.

@DennisTismenko
Copy link
Contributor

Pushed the suggested order changes to the creation of masked_verts.

@timhoffm timhoffm merged commit 382be60 into matplotlib:master Mar 22, 2020
@timhoffm
Copy link
Member

Thanks to all who have contributed to this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants