From a5276c3bd3ccf478662f7dd42ed0d37ac26c847d Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Thu, 8 Mar 2018 15:09:36 -0800 Subject: [PATCH] fix: scatterplotwidget behaves nicely when data contains infs Add methods to make it easier to programatically configure scatterplotwidget --- pyqtgraph/widgets/ColorMapWidget.py | 5 +++++ pyqtgraph/widgets/DataFilterWidget.py | 13 +++++++++---- pyqtgraph/widgets/ScatterPlotWidget.py | 19 +++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pyqtgraph/widgets/ColorMapWidget.py b/pyqtgraph/widgets/ColorMapWidget.py index bd5668ae..7e6bfab7 100644 --- a/pyqtgraph/widgets/ColorMapWidget.py +++ b/pyqtgraph/widgets/ColorMapWidget.py @@ -42,6 +42,11 @@ class ColorMapWidget(ptree.ParameterTree): def restoreState(self, state): self.params.restoreState(state) + def addColorMap(self, name): + """Add a new color mapping and return the created parameter. + """ + return self.params.addNew(name) + class ColorMapParameter(ptree.types.GroupParameter): sigColorMapChanged = QtCore.Signal(object) diff --git a/pyqtgraph/widgets/DataFilterWidget.py b/pyqtgraph/widgets/DataFilterWidget.py index cae8be86..23cf930f 100644 --- a/pyqtgraph/widgets/DataFilterWidget.py +++ b/pyqtgraph/widgets/DataFilterWidget.py @@ -30,7 +30,12 @@ class DataFilterWidget(ptree.ParameterTree): def parameters(self): return self.params - + + def addFilter(self, name): + """Add a new filter and return the created parameter item. + """ + return self.params.addNew(name) + class DataFilterParameter(ptree.types.GroupParameter): @@ -47,10 +52,10 @@ class DataFilterParameter(ptree.types.GroupParameter): def addNew(self, name): mode = self.fields[name].get('mode', 'range') if mode == 'range': - self.addChild(RangeFilterItem(name, self.fields[name])) + child = self.addChild(RangeFilterItem(name, self.fields[name])) elif mode == 'enum': - self.addChild(EnumFilterItem(name, self.fields[name])) - + child = self.addChild(EnumFilterItem(name, self.fields[name])) + return child def fieldNames(self): return self.fields.keys() diff --git a/pyqtgraph/widgets/ScatterPlotWidget.py b/pyqtgraph/widgets/ScatterPlotWidget.py index e0071f24..bd0eb908 100644 --- a/pyqtgraph/widgets/ScatterPlotWidget.py +++ b/pyqtgraph/widgets/ScatterPlotWidget.py @@ -83,7 +83,19 @@ class ScatterPlotWidget(QtGui.QSplitter): item = self.fieldList.addItem(item) self.filter.setFields(fields) self.colorMap.setFields(fields) - + + def setSelectedFields(self, *fields): + self.fieldList.itemSelectionChanged.disconnect(self.fieldSelectionChanged) + try: + self.fieldList.clearSelection() + for f in fields: + i = self.fields.keys().index(f) + item = self.fieldList.item(i) + item.setSelected(True) + finally: + self.fieldList.itemSelectionChanged.connect(self.fieldSelectionChanged) + self.fieldSelectionChanged() + def setData(self, data): """ Set the data to be processed and displayed. @@ -114,7 +126,6 @@ class ScatterPlotWidget(QtGui.QSplitter): else: self.filterText.setText('\n'.join(desc)) self.filterText.setVisible(True) - def updatePlot(self): self.plot.clear() @@ -177,9 +188,9 @@ class ScatterPlotWidget(QtGui.QSplitter): ## mask out any nan values mask = np.ones(len(xy[0]), dtype=bool) if xy[0].dtype.kind == 'f': - mask &= ~np.isnan(xy[0]) + mask &= np.isfinite(xy[0]) if xy[1] is not None and xy[1].dtype.kind == 'f': - mask &= ~np.isnan(xy[1]) + mask &= np.isfinite(xy[1]) xy[0] = xy[0][mask] style['symbolBrush'] = colors[mask]