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
[BUG] plot_roi cannot handle cmap with only 1 level #4255
Comments
This worked in previous versions. I suspect this was brought on by I stared at it for a while, and I couldn't quite spot the change that would bring on the error. I will say the tick values looked suspect, as they included a negative value. But modifying that line did not fix the issue. |
I haven't gotten that far, but it looks like the |
@adelavega |
# Paste your code here
from nilearn import plotting as niplt
import numpy as np
import nibabel as nib
import matplotlib.pyplot as plt
def main():
array_data = np.arange(24, dtype=np.int16).reshape((2, 3, 4))
array_data[:] = 0
array_data[0, 1, 1] = 1
affine = np.diag([1, 2, 3, 1])
img = nib.Nifti1Image(array_data, affine)
clust_ids = list(np.unique(img.get_fdata())[1:])
cmap = plt.cm.get_cmap("tab20", len(clust_ids))
cmap = plt.cm.get_cmap("tab20", len(clust_ids))
try:
niplt.plot_roi(img, alpha=0.8, colorbar=True, cmap=cmap)
print("good")
return 0
except IndexError:
print("bad")
return 1
except Exception:
print("skipped")
return 125
if __name__ == "__main__":
exit(main()) git bisect start
git bisect good 0.10.2
git bisect bad 0.10.3
git bisect run python tmp.py c018480 is the first bad commit [ENH] Allow setting |
OK adding back this thresholding fixed the bug |
once this is fixed, let me know if we should plan a bug fix release in case this is mission critical for some other downstream package. |
Remi, amazing! I need to learn your debugging skills because I went down a rabbit hole last night :) This does cause https://github.com/neurostuff/nimare tests to fail currently. It's not extremely urgent although I would imagine a cmap with a single level is not an uncommon usage pattern (e.g. for masks, clusters). |
For the git bisect part: https://www.youtube.com/watch?v=C2C7FTI8nB4 For the rest, print debugging did most of the work... Actually I would not have minded a couple of extra unit tests for some internal methods, maybe worth adding in this PR. |
@bthirion |
I think so. |
Is there an existing issue for this?
Operating system
Operating system version
For example one of the following:
Python version
nilearn version
0.10.3
Expected behavior
Plot ROI as usual
Current behavior & error messages
Given an image with only one level (i.e. 0s and 1s), and a custom cmap,
plot_roi
throws an error constructing thecolor_bar
.Steps and code to reproduce bug
The text was updated successfully, but these errors were encountered: