Skip to content

Commit 0dcb285

Browse files
committed
Improve colorbar connectivity plot
1 parent 5070f33 commit 0dcb285

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

nigsp/viz.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
FIGSIZE_LONG = (12, 4)
3232

3333

34-
def plot_connectivity(mtx, filename=None, title=None, closeplot=False):
34+
def plot_connectivity(mtx, filename=None, title=None, crange=None, closeplot=False):
3535
"""
3636
Create a connectivity matrix plot.
3737
@@ -45,6 +45,8 @@ def plot_connectivity(mtx, filename=None, title=None, closeplot=False):
4545
The path to save the plot on disk.
4646
title : None or str, optional
4747
Add a title to the graph
48+
range : None or list, optional
49+
Set vmin and vmax
4850
closeplot : bool, optional
4951
Whether to close plots after saving or not. Mainly used for debug
5052
or use with live python/ipython instances.
@@ -89,7 +91,24 @@ def plot_connectivity(mtx, filename=None, title=None, closeplot=False):
8991
LGR.info("Creating connectivity plot.")
9092
fig = plt.figure(figsize=FIGSIZE_SQUARE)
9193
ax = fig.subplots()
92-
plot_matrix(mtx, axes=ax)
94+
95+
pc_args = {"mat": mtx, "axes": ax}
96+
if crange is not None:
97+
if type(crange) in [list, tuple]:
98+
pc_args["vmin"] = crange[0]
99+
pc_args["vmax"] = crange[1]
100+
else:
101+
vmax = np.nanpercentile(mtx, 98) # mtx.max()
102+
vmin = np.abs(np.nanpercentile(mtx, 2)) # mtx.min()
103+
if crange == "auto-symm" and mtx.min() < 0 and vmax > 0:
104+
pc_args["vmax"] = vmax if vmax > vmin else vmin
105+
pc_args["vmin"] = -vmin if vmin > vmax else -vmax
106+
elif crange == "auto-zero" or mtx.min() > 0 or vmax < 0:
107+
pass
108+
else:
109+
raise NotImplementedError(f"{crange} option not implemented.")
110+
111+
plot_matrix(**pc_args)
93112
if title is not None:
94113
fig.suptitle(title)
95114

0 commit comments

Comments
 (0)