Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions fastplotlib/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@


def get_cmap(name: str, alpha: float = 1.0) -> np.ndarray:
"""
Get a colormap as numpy array

Parameters
----------
name: str
name of colormap
alpha: float
alpha, 0.0 - 1.0

Returns
-------
np.ndarray
[n_colors, 4], i.e. [n_colors, RGBA]

"""

cmap_path = Path(__file__).absolute().parent.joinpath("colormaps", name)
if cmap_path.is_file():
cmap = np.loadtxt(cmap_path)
Expand Down Expand Up @@ -214,6 +231,9 @@ def calculate_gridshape(n_subplots: int) -> Tuple[int, int]:

def normalize_min_max(a):
"""normalize an array between 0 - 1"""
if np.unique(a).size == 1:
return np.zeros(a.size)

return (a - np.min(a)) / (np.max(a - np.min(a)))


Expand Down