Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 430f513

Browse filesBrowse files
authored
fix normalize_min_max (#353)
* fix normalize_min_max * document utils.get_cmap()
1 parent 1ef8eab commit 430f513
Copy full SHA for 430f513

File tree

1 file changed

+20
-0
lines changed
Filter options

1 file changed

+20
-0
lines changed

‎fastplotlib/utils/functions.py

Copy file name to clipboardExpand all lines: fastplotlib/utils/functions.py
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626

2727

2828
def get_cmap(name: str, alpha: float = 1.0) -> np.ndarray:
29+
"""
30+
Get a colormap as numpy array
31+
32+
Parameters
33+
----------
34+
name: str
35+
name of colormap
36+
alpha: float
37+
alpha, 0.0 - 1.0
38+
39+
Returns
40+
-------
41+
np.ndarray
42+
[n_colors, 4], i.e. [n_colors, RGBA]
43+
44+
"""
45+
2946
cmap_path = Path(__file__).absolute().parent.joinpath("colormaps", name)
3047
if cmap_path.is_file():
3148
cmap = np.loadtxt(cmap_path)
@@ -214,6 +231,9 @@ def calculate_gridshape(n_subplots: int) -> Tuple[int, int]:
214231

215232
def normalize_min_max(a):
216233
"""normalize an array between 0 - 1"""
234+
if np.unique(a).size == 1:
235+
return np.zeros(a.size)
236+
217237
return (a - np.min(a)) / (np.max(a - np.min(a)))
218238

219239

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.