Skip to content
Snippets Groups Projects

Viz add colorbar

+ 11
0
@@ -8,6 +8,7 @@ from typing import List, Optional, Union
import dask.array as da
import ipywidgets as widgets
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import qim3d
@@ -28,6 +29,7 @@ def slices(
show_position: bool = True,
interpolation: Optional[str] = "none",
img_size=None,
cbar: bool = False,
**imshow_kwargs,
) -> plt.Figure:
"""Displays one or several slices from a 3d volume.
@@ -50,6 +52,7 @@ def slices(
show (bool, optional): If True, displays the plot (i.e. calls plt.show()). Defaults to False.
show_position (bool, optional): If True, displays the position of the slices. Defaults to True.
interpolation (str, optional): Specifies the interpolation method for the image. Defaults to None.
cbar (bool, optional): Adds a colorbar positioned in the top-right for the corresponding colormap and data range. Defaults to False.
Returns:
fig (matplotlib.figure.Figure): The figure with the slices from the 3d array.
@@ -181,6 +184,11 @@ def slices(
# Hide the axis, so that we have a nice grid
ax.axis("off")
if cbar:
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
mappable = matplotlib.cm.ScalarMappable(norm=norm, cmap=cmap)
fig.colorbar(mappable=mappable, ax=np.atleast_1d(axs[0])[-1], orientation='vertical')
if show:
plt.show()
@@ -216,6 +224,7 @@ def slicer(
show_position: bool = False,
interpolation: Optional[str] = "none",
img_size=None,
cbar: bool = False,
**imshow_kwargs,
) -> widgets.interactive:
"""Interactive widget for visualizing slices of a 3D volume.
@@ -230,6 +239,7 @@ def slicer(
img_width (int, optional): Width of the figure. Defaults to 3.
show_position (bool, optional): If True, displays the position of the slices. Defaults to False.
interpolation (str, optional): Specifies the interpolation method for the image. Defaults to None.
cbar (bool, optional): Adds a colorbar for the corresponding colormap and data range. Defaults to False.
Returns:
slicer_obj (widgets.interactive): The interactive widget for visualizing slices of a 3D volume.
@@ -263,6 +273,7 @@ def slicer(
position=position,
n_slices=1,
show=True,
cbar=cbar,
**imshow_kwargs,
)
return fig
Loading