fixed some bugs in ScatterPlot's handling of meta-data
This commit is contained in:
parent
e962f4b7f4
commit
2a412a3e28
@ -128,12 +128,13 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
numPts = 0
|
numPts = 0
|
||||||
|
|
||||||
## create empty record array
|
## create empty record array
|
||||||
self.data = np.empty(numPts, dtype=[('x', float), ('y', float), ('size', float), ('symbol', 'S1'), ('pen', object), ('brush', object), ('data', object), ('spot', object)])
|
self.data = np.empty(numPts, dtype=[('x', float), ('y', float), ('size', float), ('symbol', 'S1'), ('pen', object), ('brush', object), ('spot', object)])
|
||||||
self.data['size'] = -1 ## indicates use default size
|
self.data['size'] = -1 ## indicates use default size
|
||||||
self.data['symbol'] = ''
|
self.data['symbol'] = ''
|
||||||
self.data['pen'] = None
|
self.data['pen'] = None
|
||||||
self.data['brush'] = None
|
self.data['brush'] = None
|
||||||
self.data['data'] = None
|
self.pointData = np.empty(numPts, dtype=object)
|
||||||
|
self.pointData[:] = None
|
||||||
|
|
||||||
if 'spots' in kargs:
|
if 'spots' in kargs:
|
||||||
spots = kargs['spots']
|
spots = kargs['spots']
|
||||||
@ -152,8 +153,10 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
x,y = pos[0], pos[1]
|
x,y = pos[0], pos[1]
|
||||||
self.data[i]['x'] = x
|
self.data[i]['x'] = x
|
||||||
self.data[i]['y'] = y
|
self.data[i]['y'] = y
|
||||||
elif k in ['x', 'y', 'size', 'symbol', 'data']:
|
elif k in ['x', 'y', 'size', 'symbol']:
|
||||||
self.data[i][k] = spot[k]
|
self.data[i][k] = spot[k]
|
||||||
|
elif k == 'data':
|
||||||
|
self.pointData[i] = spot[k]
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown spot parameter: %s" % k)
|
raise Exception("Unknown spot parameter: %s" % k)
|
||||||
elif 'y' in kargs:
|
elif 'y' in kargs:
|
||||||
@ -167,7 +170,7 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
setMethod = getattr(self, 'set' + k[0].upper() + k[1:])
|
setMethod = getattr(self, 'set' + k[0].upper() + k[1:])
|
||||||
setMethod(kargs[k])
|
setMethod(kargs[k])
|
||||||
|
|
||||||
if 'data' in kargs:
|
if 'data' in kargs:
|
||||||
self.setPointData(kargs['data'])
|
self.setPointData(kargs['data'])
|
||||||
|
|
||||||
self.updateSpots()
|
self.updateSpots()
|
||||||
@ -286,7 +289,7 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
raise Exception("Must set xy data before setting meta data.")
|
raise Exception("Must set xy data before setting meta data.")
|
||||||
if len(data) != len(self.data):
|
if len(data) != len(self.data):
|
||||||
raise Exception("Length of meta data does not match number of points (%d != %d)" % (len(data), len(self.data)))
|
raise Exception("Length of meta data does not match number of points (%d != %d)" % (len(data), len(self.data)))
|
||||||
self.data['data'] = data
|
self.pointData = data
|
||||||
self.updateSpots()
|
self.updateSpots()
|
||||||
|
|
||||||
|
|
||||||
@ -385,11 +388,6 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
symbol = self.data['symbol'].copy()
|
symbol = self.data['symbol'].copy()
|
||||||
symbol[symbol==''] = self.opts['symbol']
|
symbol[symbol==''] = self.opts['symbol']
|
||||||
|
|
||||||
data = self.data['data'].copy()
|
|
||||||
if 'data' in self.opts:
|
|
||||||
data[data==None] = self.opts['data']
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for i in xrange(len(self.data)):
|
for i in xrange(len(self.data)):
|
||||||
s = self.data[i]
|
s = self.data[i]
|
||||||
@ -399,6 +397,11 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
else:
|
else:
|
||||||
psize = size[i]
|
psize = size[i]
|
||||||
|
|
||||||
|
if self.pointData is None or self.pointData[i] is None:
|
||||||
|
data = self.opts['data']
|
||||||
|
else:
|
||||||
|
data = self.pointData[i]
|
||||||
|
|
||||||
#if xmn is None:
|
#if xmn is None:
|
||||||
#xmn = pos[0]-psize
|
#xmn = pos[0]-psize
|
||||||
#xmx = pos[0]+psize
|
#xmx = pos[0]+psize
|
||||||
@ -410,7 +413,7 @@ class ScatterPlotItem(GraphicsObject):
|
|||||||
#ymn = min(ymn, pos[1]-psize)
|
#ymn = min(ymn, pos[1]-psize)
|
||||||
#ymx = max(ymx, pos[1]+psize)
|
#ymx = max(ymx, pos[1]+psize)
|
||||||
|
|
||||||
item = self.mkSpot(pos, size[i], self.opts['pxMode'], brush[i], pen[i], data[i], symbol=symbol[i], index=len(self.spots))
|
item = self.mkSpot(pos, size[i], self.opts['pxMode'], brush[i], pen[i], data, symbol=symbol[i], index=len(self.spots))
|
||||||
self.spots.append(item)
|
self.spots.append(item)
|
||||||
self.data[i]['spot'] = item
|
self.data[i]['spot'] = item
|
||||||
#if self.optimize:
|
#if self.optimize:
|
||||||
|
Loading…
Reference in New Issue
Block a user