Skip to content
Snippets Groups Projects
Commit 2a8b7ed0 authored by David Johansen's avatar David Johansen
Browse files

changed vrange behaviour for cbar=True

parent 6b89e43a
Branches
No related tags found
1 merge request!124Viz add colorbar
This commit is part of merge request !124. Comments created here will be created in the context of that merge request.
......@@ -137,6 +137,11 @@ def slices(
if isinstance(vol, da.core.Array):
vol = vol.compute()
if cbar:
# In this case, we want the vrange to be constant across the slices, which makes them all comparable to a single cbar.
new_vmin = vmin if vmin else np.min(vol)
new_vmax = vmax if vmax else np.max(vol)
# Run through each ax of the grid
for i, ax_row in enumerate(axs):
for j, ax in enumerate(np.atleast_1d(ax_row)):
......@@ -144,10 +149,12 @@ def slices(
try:
slice_img = vol.take(slice_idxs[slice_idx], axis=axis)
if not cbar:
# If vmin is higher than the highest value in the image ValueError is raised
# We don't want to override the values because next slices might be okay
new_vmin = None if (isinstance(vmin, (float, int)) and vmin > np.max(slice_img)) else vmin
new_vmax = None if (isinstance(vmax, (float, int)) and vmax < np.min(slice_img)) else vmax
ax.imshow(
slice_img, cmap=cmap, interpolation=interpolation,vmin = new_vmin, vmax = new_vmax, **imshow_kwargs
)
......@@ -185,7 +192,7 @@ def slices(
ax.axis("off")
if cbar:
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
norm = matplotlib.colors.Normalize(vmin=new_vmin, vmax=new_vmax, clip=True)
mappable = matplotlib.cm.ScalarMappable(norm=norm, cmap=cmap)
fig.colorbar(mappable=mappable, ax=np.atleast_1d(axs[0])[-1], orientation='vertical')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment