-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[WIP] Attempted fix to colorbar bug when yscaled len = 1 as suggested in previous PR #24656
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
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
Please indicate the issue being fixed, and include code snippet that you are testing with. |
The issue being addressed is handling automin and automax when yscaled len = 1, in the def _proportional_y function in test/colorbar.py.
The (failing) test generating the warning is:
Looking at the stack trace, the warning seems to come from self.ax.set_ylim(lower, upper) where lower == upper. Looking for other instances of this particular warning (such as here), it appears to come from setting the min and max y values to be the same. This makes me question what the expected behavior from the test should be. |
The original code for reproduction of this issue is import matplotlib.pyplot as plt
fig, ax = plt.subplots()
cs = ax.contour([[1, 1], [1, 1]])
fig.colorbar(cs, ax=ax)
plt.show() However, this seems to yield the following TypeError TypeError: Input z must be 2D, not 1D The same TypeError also occurs if we change cs = ax.contour([[1, 1], [1, 1]]) to cs = ax.contour([[1, 2], [3, 4]]) This TypeError is resulted from lib/matplotlib/contour.py, line 1526, in _initialize_x_y, which makes me think that rather than a colorbar problem, the root of this issue lies in how contour works. What is the expected behavior of the original code for reproduction? If we aren't supposed to call Fontour on input like above in the first place, how is Colorbar supposed to behave and why does the the API warning even matter? I was able to suppress the failed test case with the following change to @quinnah's test case. def test_contour_uniformfield_colorbar():
# Smoke test for issue
fig, ax = plt.subplots()
with pytest.warns(Warning) as record:
cs = ax.contour([[2, 2], [2, 2]])
assert len(record) == 1
try:
fig.colorbar(cs, ax=ax)
except:
pass |
Hi @quinnah - is this ready for review? Do you need help with moving this forward? Cheers! |
PR Summary
Opening a draft PR for issue #23817, building off the work of @Andes0113 in PR #23984 and attempting to address the issues mentioned there.
When I run the test, I'm able to fix the underlying issue by using the same yscaled value for
automin and automax. However, later on in the test, I run into a warning on the
fig.colorbar(cs, ax)
:When I look at the stack trace, I see the following (I omitted decorator wrapping frames):
This makes me think that the warning has to do with the axis set on the plot. Online, posts seem to suggest that this error comes up when generating plots with no spread in the y-axis. That zero-width
spread on the y-axis seems critical to the test though, so I'm not sure how to proceed.
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst