Merge pull request #645 from campagnola/scatterplotwidget-update

fix: scatterplotwidget behaves nicely when data contains infs
This commit is contained in:
Luke Campagnola 2018-03-09 10:17:05 -08:00 committed by GitHub
commit ee0877170d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 8 deletions

View File

@ -42,6 +42,11 @@ class ColorMapWidget(ptree.ParameterTree):
def restoreState(self, state): def restoreState(self, state):
self.params.restoreState(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): class ColorMapParameter(ptree.types.GroupParameter):
sigColorMapChanged = QtCore.Signal(object) sigColorMapChanged = QtCore.Signal(object)

View File

@ -31,6 +31,11 @@ class DataFilterWidget(ptree.ParameterTree):
def parameters(self): def parameters(self):
return self.params 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): class DataFilterParameter(ptree.types.GroupParameter):
@ -47,10 +52,10 @@ class DataFilterParameter(ptree.types.GroupParameter):
def addNew(self, name): def addNew(self, name):
mode = self.fields[name].get('mode', 'range') mode = self.fields[name].get('mode', 'range')
if mode == 'range': if mode == 'range':
self.addChild(RangeFilterItem(name, self.fields[name])) child = self.addChild(RangeFilterItem(name, self.fields[name]))
elif mode == 'enum': elif mode == 'enum':
self.addChild(EnumFilterItem(name, self.fields[name])) child = self.addChild(EnumFilterItem(name, self.fields[name]))
return child
def fieldNames(self): def fieldNames(self):
return self.fields.keys() return self.fields.keys()

View File

@ -84,6 +84,18 @@ class ScatterPlotWidget(QtGui.QSplitter):
self.filter.setFields(fields) self.filter.setFields(fields)
self.colorMap.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): def setData(self, data):
""" """
Set the data to be processed and displayed. Set the data to be processed and displayed.
@ -115,7 +127,6 @@ class ScatterPlotWidget(QtGui.QSplitter):
self.filterText.setText('\n'.join(desc)) self.filterText.setText('\n'.join(desc))
self.filterText.setVisible(True) self.filterText.setVisible(True)
def updatePlot(self): def updatePlot(self):
self.plot.clear() self.plot.clear()
if self.data is None: if self.data is None:
@ -177,9 +188,9 @@ class ScatterPlotWidget(QtGui.QSplitter):
## mask out any nan values ## mask out any nan values
mask = np.ones(len(xy[0]), dtype=bool) mask = np.ones(len(xy[0]), dtype=bool)
if xy[0].dtype.kind == 'f': 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': 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] xy[0] = xy[0][mask]
style['symbolBrush'] = colors[mask] style['symbolBrush'] = colors[mask]