We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 351512e commit 1376d00Copy full SHA for 1376d00
1 file changed
plotpy/io.py
@@ -64,6 +64,12 @@ def scale_data_to_dtype(data: np.ndarray, dtype: np.dtype) -> np.ndarray:
64
info = np.iinfo(dtype)
65
dmin = data.min()
66
dmax = data.max()
67
+ if dmax == dmin:
68
+ # Constant data: avoid 0/0 division (which would yield NaN). Map every
69
+ # sample to the dtype range minimum so downstream image rendering keeps
70
+ # working instead of seeing NaNs.
71
+ data = np.full_like(data, float(info.min))
72
+ return np.array(data, dtype)
73
data -= dmin
74
data = data * float(info.max - info.min) / (dmax - dmin)
75
data = data + float(info.min)
0 commit comments