Skip to content

Commit

Permalink
Improve colorbar connectivity plot
Browse files Browse the repository at this point in the history
  • Loading branch information
smoia committed May 19, 2023
1 parent 9ba5de1 commit c95d33d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nigsp/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
FIGSIZE_LONG = (12, 4)


def plot_connectivity(mtx, filename=None, title=None, closeplot=False):
def plot_connectivity(mtx, filename=None, title=None, crange=None, closeplot=False):
"""
Create a connectivity matrix plot.
Expand All @@ -45,6 +45,8 @@ def plot_connectivity(mtx, filename=None, title=None, closeplot=False):
The path to save the plot on disk.
title : None or str, optional
Add a title to the graph
range : None or list, optional
Set vmin and vmax
closeplot : bool, optional
Whether to close plots after saving or not. Mainly used for debug
or use with live python/ipython instances.
Expand Down Expand Up @@ -89,7 +91,24 @@ def plot_connectivity(mtx, filename=None, title=None, closeplot=False):
LGR.info("Creating connectivity plot.")
fig = plt.figure(figsize=FIGSIZE_SQUARE)
ax = fig.subplots()
plot_matrix(mtx, axes=ax)

pc_args = {"mat": mtx, "axes": ax}
if crange is not None:
if type(crange) in [list, tuple]:
pc_args["vmin"] = crange[0]
pc_args["vmax"] = crange[1]
else:
vmax = np.nanpercentile(mtx, 98) # mtx.max()
vmin = np.abs(np.nanpercentile(mtx, 2)) # mtx.min()
if crange == "auto-symm" and mtx.min() < 0 and vmax > 0:
pc_args["vmax"] = vmax if vmax > vmin else vmin
pc_args["vmin"] = -vmin if vmin > vmax else -vmax
elif crange == "auto-zero" or mtx.min() > 0 or vmax < 0:
pass
else:
raise NotImplementedError(f"{crange} option not implemented.")

plot_matrix(**pc_args)
if title is not None:
fig.suptitle(title)

Expand Down

0 comments on commit c95d33d

Please sign in to comment.