Fill in non-finite plot values for Qt versions >= 5.12.3#1287
Fill in non-finite plot values for Qt versions >= 5.12.3#1287j9ac9k merged 2 commits intopyqtgraph:masterfrom
Conversation
pyqtgraph/functions.py
Outdated
| idx[:first] = first | ||
| arr[1:-1] = arr[1:-1][idx] |
There was a problem hiding this comment.
| idx[:first] = first | |
| arr[1:-1] = arr[1:-1][idx] | |
| if first < len(x): | |
| # Replace all non-finite entries from beginning of arr with the first finite one | |
| idx[:first] = first | |
| arr[1:-1] = arr[1:-1][idx] |
Fixes the case where the whole buffer contains non-finite items in x or y (or both).
|
I'm still hitting a case where everything just freezes with my all Y values being NaN buffer, so I can't really validate the code.. I'm not sure if it's related to the Also, could it be that with the fill-in solution, that for time-series, where the X-axis is generally the (finite) timestamp, filling-in values will overwrite the timestamps of the points that aren't rendered and thus cause auto-scaling to behave differently since the NaN-cleaned version of the buffer will have a different starting point? if qtver >= [5, 12, 3]:
isfinite = np.isfinite(x) & np.isfinite(y)
isfinite_x = np.isfinite(x)
isfinite_y = np.isfinite(y)
if not np.all(isfinite_x):
# credit: Divakar https://stackoverflow.com/a/41191127/643629
mask = ~isfinite_x
idx = np.arange(len(x))
idx[mask] = -1
np.maximum.accumulate(idx, out=idx)
first = np.searchsorted(idx, 0)
if first < len(x):
# Replace all non-finite X-axis points from beginning of arr with the first finite one
idx[:first] = first # np.max(first, len(x) - 1)
arr[1:-1] = arr[1:-1][idx]
if not np.all(isfinite_y):
mask = ~isfinite_y
# Replace all non-finite Y-axis points with 0
arr[1:-1]['y'][mask] = 0 |
Fixes #1057
I have only manually tested this for a few cases; it would be nice to have some test coverage here before merging.