-
Notifications
You must be signed in to change notification settings - Fork 580
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] avg_method
and symmetric_cbar
flags using plot_surf_stat_map
working properly with plotly engine
#4296
Comments
avg_method
and symmetric_cbar
flags in plotly not working properly
avg_method
and symmetric_cbar
flags in plotly not working properlyavg_method
and symmetric_cbar
flags using plot_surf_stat_map
with plotly not working properly
avg_method
and symmetric_cbar
flags using plot_surf_stat_map
with plotly not working properlyavg_method
and symmetric_cbar
flags using plot_surf_stat_map
working properly with plotly engine
Thx for reporting. Could you make it work with images provided or generated by Nilearn ? This would make it easier for us. |
For the avg_method, the error you are getting is because nilearn/nilearn/plotting/surf_plotting.py Line 1158 in 1afacef
Also note that avg_method is not implemented for plotly: |
quick check and removing that |
I can reproduce the symmetric_bar issue with plotly with this code. import numpy as np
from nilearn import datasets, plotting, surface
import matplotlib.pyplot as plt
stat_img = datasets.load_sample_motor_activation_image()
fsaverage = datasets.fetch_surf_fsaverage()
curv_right = surface.load_surf_data(fsaverage.curv_right)
curv_right_sign = np.sign(curv_right)
texture = surface.vol_to_surf(stat_img, fsaverage.pial_right)
engine = "matplotlib"
plotting.plot_surf_stat_map(
fsaverage.infl_right,
texture,
hemi="right",
title="Surface right hemisphere",
colorbar=True,
threshold=1.0,
bg_map=curv_right_sign,
engine=engine,
symmetric_cbar=False,
)
plt.show()
engine = "plotly"
print(f"Using plotting engine {engine}.")
fig = plotting.plot_surf_stat_map(
fsaverage.infl_right,
texture,
hemi="right",
title="Surface right hemisphere",
colorbar=True,
threshold=1.0,
bg_map=curv_right_sign,
bg_on_data=True,
engine=engine,
symmetric_cbar=False,
)
fig.show() |
Will open a draft PR to discuss this... |
Thanks for your quick response! Please let me know if I can help in any way. |
probably explained by the fact that a statistical map is a 3D volume to there is only one value along the 4th dimension, so min, max, mean will always be the same. |
Probably it's my mistake, but I assumed that the average was done at a vertex/face level. Also, in this case you pass the statistical map as a texture, not as a 3D volume per se, so I'm not sure how it would affect. About the colorbar issue, I tested the fixes in your pull request and it seems to do the trick. Thanks for your help. |
Gosh... You are completely correct... |
I was trying to stay close to the code you provided but this did lead me to try passing the path to a nifti image as stat map as import matplotlib.pyplot as plt
import numpy as np
from nilearn import datasets, plotting, surface
fsaverage = datasets.fetch_surf_fsaverage()
curv_left = surface.load_surf_data(fsaverage.curv_left)
curv_left_sign = np.sign(curv_left)
stat_map = datasets.load_sample_motor_activation_image()
print(stat_map)
# %%
engine = "matplotlib"
plotting.plot_surf_stat_map(
fsaverage.infl_left,
stat_map = stat_map,
hemi="left",
title="Surface left hemisphere",
cmap = 'bwr',
colorbar=True,
threshold=1.0,
bg_map=curv_left_sign,
engine=engine,
symmetric_cbar=False,
avg_method="mean",
) gives
|
OK so I will split this into several PR to solve because there is more than one issue:
|
For the Just writing downs the things to check.
|
Note passing a negative values as threshold is ignored and does not throw warnings: """Test plotting asymmetric color bar."""
import matplotlib.pyplot as plt
import numpy as np
from nilearn import datasets, plotting, surface
from nilearn.image import threshold_img
vmin = None
vmax = None
symmetric_cbar = False
threshold = -0.5
stat_img = datasets.load_sample_motor_activation_image()
fsaverage = datasets.fetch_surf_fsaverage()
curv_right = surface.load_surf_data(fsaverage.curv_right)
curv_right_sign = np.sign(curv_right)
texture = surface.vol_to_surf(stat_img, fsaverage.pial_right)
engine = "matplotlib"
plotting.plot_surf_stat_map(
fsaverage.infl_right,
texture,
hemi="right",
title="Surface right hemisphere",
colorbar=True,
threshold=threshold,
bg_map=curv_right_sign,
engine=engine,
symmetric_cbar=False,
cmap="black_red",
vmin = vmin,
vmax = vmax
)
plt.show() gives Where as I would expect the same as for |
Tried passing invalid values to |
Is there an existing issue for this?
Operating system
Operating system version
Debian testing (trixie)
Python version
nilearn version
0.10.3
Expected behavior
When using the plotly engine, the colorbar should not be symmetric if symmetric_cbar=False. The avg_method should be user settable. This seems related to #3941 bug.
Current behavior & error messages
This is what I got:
The flag symmetric_cbar=False is ignored, always plotting symmetric colorbars. On the other hand, when avg_method flag is inserted, I get the following error:
Steps and code to reproduce bug
The text was updated successfully, but these errors were encountered: