From 5373458f3e32355e06e9fd342ba1dbf51d120158 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Wed, 1 Nov 2023 04:37:37 -0400 Subject: [PATCH 1/2] fix normalize_min_max --- fastplotlib/utils/functions.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index 3013559d5..1acd23fad 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -214,6 +214,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))) From 1a21b7129715b9d48f1428307f580708ffaf9cb8 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Wed, 1 Nov 2023 04:48:27 -0400 Subject: [PATCH 2/2] document utils.get_cmap() --- fastplotlib/utils/functions.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index 1acd23fad..8d1e8694f 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -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)