Skip to content
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

Handle argument "facecolors=None" correctly in plot_surface() #24727

Merged
merged 8 commits into from Dec 30, 2022

Conversation

ocastany
Copy link
Contributor

PR Summary

Handle plot_surface(facecolors=None) correctly.
This patch avoids the error: UnboundLocalError: local variable 'color' referenced before assignment.

PR Checklist

Documentation and Tests

  • [N/A] Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@rcomer
Copy link
Member

rcomer commented Dec 14, 2022

Thank you for your contribution @ocastany. Could you provide an example that demonstrates the problem you are fixing?

@ocastany
Copy link
Contributor Author

Here is an example showing the problem before the patch:

> from pylab import *
> fig = figure()
> ax = fig.add_subplot(projection='3d')
> X,Y = meshgrid(arange(5), arange(5))
> Z = sqrt(X**2 + Y**2)
> ax.plot_surface(X,Y,Z, facecolors=None)

UnboundLocalError: local variable 'color' referenced before assignment

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

Could you add your example as a test so this doesn't come back again in the future?

lib/mpl_toolkits/mplot3d/axes3d.py Outdated Show resolved Hide resolved
Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
@ocastany
Copy link
Contributor Author

Sorry, I don't know where and how to "add my example as a test".

@melissawm
Copy link
Contributor

Hi @ocastany - you can look at the test_axes3d.py file and add your example as a test that needs to pass. You can also look at https://matplotlib.org/stable/devel/testing.html for more details on writing and verifying tests for Matplotlib. Cheers!

@ocastany
Copy link
Contributor Author

I added a test function in my GitHub repository. Can you use it?

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

Yep, I can see your test and it looks good! Just a minor suggestion that we can do an image comparison that the facecolors=None explicit argument should do the same thing as the default. We have a test decorator to help with that which I've added as a suggestion.

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py Outdated Show resolved Hide resolved
Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
@ocastany
Copy link
Contributor Author

This looks good to me

@greglucas
Copy link
Contributor

pre-commit.ci autofix

@greglucas
Copy link
Contributor

Sorry @ocastany, it looks like the suggestions I had added additional white-space on some lines. precommit.ci can't autofix these because the PR is from your protected branch, so I suggested some additional changes to remove that which you will have to commit to your own branch.

ocastany and others added 2 commits December 29, 2022 23:47
Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
Co-authored-by: Greg Lucas <greg.m.lucas@gmail.com>
@greglucas greglucas merged commit c069b30 into matplotlib:main Dec 30, 2022
@greglucas
Copy link
Contributor

Thanks, @ocastany!

@QuLogic QuLogic added this to the v3.7.0 milestone Dec 30, 2022
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.

None yet

5 participants