Open
Description
If your issue is a usage question, please consider asking on the
MNE Forum instead of opening an issue.
Describe the problem
The default colormap for mne-connectivity.viz.plot_connectivity_circle is "hot". This colorscale only makes sense for positive values. However, my matrix contains both positive and negative values. In this case the colormap should change to a diverging map with two different colors mapping to positive and negative values (e.g. blue to red with black in the middle). 0s should correspond to the background color.
Describe your solution
I currently do this:
# If the matrix contains both negative and positive values then
# the colorscale has to have two different colors with 0 corresponding
# to the background color
facecolor = 'white'
textcolor = 'black'
if np.any(matrix_values > 0) & np.any(matrix_values < 0):
# Find the minimum and maximum values in the data and compute
# midpoint between vmin and vmax where 0 should lie
vmin = matrix_values.min()
vmax = matrix_values.max()
midpoint = abs(vmin) / (vmax - vmin)
colors = [
(0, "blue"), # Negative values: blue
(midpoint, facecolor), # Zero: black
(1, "red") # Positive values: red
]
# Create the colormap
cmap = LinearSegmentedColormap.from_list("custom_cmap",colors)
else:
cmap = 'hot'
Metadata
Assignees
Labels
No labels
Activity