-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: ValueError thrown when levels
is set to a lower value than vmin
when using contours
method of Axes
#26531
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
Comments
This appears to be related to #25247, which changed the inheritance of the In this case, it is not actually a fatal error, as far as I can tell... when I run it it continues after printing the traceback. The problem is that it is doing checks at every step, so Essentially it is first autoscalling, then applying the vmin/vmax that were specified, so it goes:
This pattern of This can be suppressed (on our end) by doing: diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py
index 79f66b8961..ab88faf28c 100644
--- a/lib/matplotlib/contour.py
+++ b/lib/matplotlib/contour.py
@@ -887,11 +887,12 @@ class ContourSet(ContourLabeler, mcoll.Collection):
self.set_cmap(cmap)
if norm is not None:
self.set_norm(norm)
- if vmin is not None:
- self.norm.vmin = vmin
- if vmax is not None:
- self.norm.vmax = vmax
- self._process_colors()
+ with self.norm.callbacks.blocked(signal="changed"):
+ if vmin is not None:
+ self.norm.vmin = vmin
+ if vmax is not None:
+ self.norm.vmax = vmax
+ self._process_colors()
if self._paths is None:
self._paths = self._make_paths_from_contour_generator() But perhaps there are more areas where such supression needs to happen? Or perhaps @anntzer thoughts? |
A better fix is likely possible, but your patch seems correct at first glance. |
(As a side point, perhaps there should be a helper method that lets one set both vmin and vmax on a norm and only trigger the validation and signals once both have been set -- in essence wrapping the patch written by @ksunden) |
Bug summary
With the recent mpl prerelease, we started to have a failure in the test suite of nilearn, a package that depends on matplotlib for visualization. I reproduced the error with a matplotlib example and it seems that when calling
Axes.contours
it's not possible to set thelevels
parameter to values less thanvmin
using array-like input. This happens even whenvmax
is also set by the user and it seems to be because vmax ends up being set to 0 internally. The code reproduced below will throwValueError: minvalue must be less than or equal to maxvalue
. I'm not sure if it's a usage error or a bug so let me know if this is expected behavior, however as I understand it the values forlevels
andvmin
andvmax
should be independent.Code for reproduction
Actual outcome
Expected outcome
A plot matplotlib.contour.QuadContourSet object
Additional information
The test that led to this failure did pass before this version
Operating system
Ubuntu 22.04
Matplotlib Version
3.8.0rc1
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.10.4
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: