Commit 18ddff76 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

colormap no longer requires scipy.interpolate

parent b398ccd0
......@@ -63,8 +63,8 @@ class ColorMap(object):
ignored. By default, the mode is entirely RGB.
=============== ==============================================================
self.pos = pos
self.color = color
self.pos = np.array(pos)
self.color = np.array(color)
if mode is None:
mode = np.ones(len(pos))
self.mode = mode
......@@ -83,11 +83,6 @@ class ColorMap(object):
qcolor Values are returned as an array of QColor objects.
=========== ===============================================================
import scipy.interpolate
raise Exception(" requires the package scipy.interpolate, but it could not be imported.")
if isinstance(mode, basestring):
mode = self.enumMap[mode.lower()]
......@@ -96,15 +91,24 @@ class ColorMap(object):
pos, color = self.getStops(mode)
data = np.clip(data, pos.min(), pos.max())
# don't need this--np.interp takes care of it.
#data = np.clip(data, pos.min(), pos.max())
if not isinstance(data, np.ndarray):
interp = scipy.interpolate.griddata(pos, color, np.array([data]))[0]
# Interpolate
# TODO: is griddata faster?
# interp = scipy.interpolate.griddata(pos, color, data)
if np.isscalar(data):
interp = np.empty((color.shape[1],), dtype=color.dtype)
interp = scipy.interpolate.griddata(pos, color, data)
if not isinstance(data, np.ndarray):
data = np.array(data)
interp = np.empty(data.shape + (color.shape[1],), dtype=color.dtype)
for i in range(color.shape[1]):
interp[...,i] = np.interp(data, pos, color[:,i])
# Convert to QColor if requested
if mode == self.QCOLOR:
if not isinstance(data, np.ndarray):
if np.isscalar(data):
return QtGui.QColor(*interp)
return [QtGui.QColor(*x) for x in interp]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment