fix bug when plotting boolean arrays (#1748)

* test and fix for plotting boolean arrays

* smaller is faster

* oh, that bool went away

* tests should keep up with optimizations
This commit is contained in:
Martin Chase 2021-04-28 21:35:27 -07:00 committed by GitHub
parent a534132c62
commit 4ee1fe4388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -639,6 +639,11 @@ class PlotDataItem(GraphicsObject):
x = self.xData
y = self.yData
if y.dtype == bool:
y = y.astype(np.uint8)
if x.dtype == bool:
x = x.astype(np.uint8)
if self.opts['fftMode']:
x,y = self._fourierTransform(x, y)
# Ignore the first bin for fft data if we have a logx scale

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
@ -5,6 +6,16 @@ from pyqtgraph.Qt import QtGui
pg.mkQApp()
def test_bool():
truths = np.random.randint(0, 2, size=(100,)).astype(bool)
pdi = pg.PlotDataItem(truths)
bounds = pdi.dataBounds(1)
assert isinstance(bounds[0], np.uint8)
assert isinstance(bounds[1], np.uint8)
xdata, ydata = pdi.getData()
assert ydata.dtype == np.uint8
def test_fft():
f = 20.
x = np.linspace(0, 1, 1000)