I would like to draw a connectome plot using self-defined color map for the links.
The following is my code. Here, sm
defined a colormap but I can not use it in built-in parameter edge_cmap
, like edge_cmap = sm
.
Moreover, I can not use edge_kwargs
to manually define colors of all the links, either. I tried edge_kwargs = {"color": sm.to_rgba(strength)}
, but it failed as it returned an rgb array can not be a valid color.
import numpy as np
import random
import matplotlib.colors as mplc
from matplotlib import cm
connectivity2 = np.zeros([len(roilist),len(roilist)])
random.seed(100)
strength = [random.random() for _ in range(len(roilist))]
connectivity2[:,1] = strength
connectivity2[1,:] = strength
cmap = mplc.ListedColormap(["steelblue","#FF4F00"])
sm = cm.ScalarMappable(norm = plt.Normalize(np.min(strength),
np.max(strength)),
cmap = cmap)
plot1_2 = plot_connectome(connectivity2,
roilist[["roundx","roundy","roundz"]],
roilist["networkcolor"],
edge_kwargs = {"linewidth":1.5,
"alpha":0.3},
display_mode = "z",
alpha = 0.2)
Thanks!