Improved drag'n'drop of data into scatter plots so that it no longer requires

matching identifiers along dimensions.
This commit is contained in:
Einar Ryeng 2007-07-30 17:42:48 +00:00
parent 0bc4a6e3f0
commit aa4007e208
3 changed files with 28 additions and 43 deletions

View File

@ -65,39 +65,6 @@ class BlmScatterPlot(plots.ScatterPlot):
self.sc = self._mappable
self.add_pc_spin_buttons(self._T.shape[1], absi, ordi)
def _update_color_from_dataset(self, data):
"""Overriding scatter for testing of colormaps.
"""
is_category = False
array = data.asarray()
#only support for 2d-arrays:
try:
m, n = array.shape
except:
raise ValueError, "No support for more than 2 dimensions."
# is dataset a vector or matrix?
if not n==1:
# we have a category dataset
if isinstance(data, fluents.dataset.CategoryDataset):
is_category = True
map_vec = scipy.dot(array, scipy.diag(scipy.arange(n))).sum(1)
else:
map_vec = array.sum(1)
else:
map_vec = array.ravel()
# update facecolors
self.sc.set_array(map_vec)
self.sc.set_clim(map_vec.min(), map_vec.max())
if is_category:
cmap = cm.Paired
else:
cmap = cm.jet
self.sc.set_cmap(cmap)
self.sc.update_scalarmappable() #sets facecolors from array
self.canvas.draw()
def set_facecolor(self, colors):
"""Set patch facecolors.
"""

View File

@ -441,41 +441,59 @@ class ScatterPlot(Plot):
def is_mappable_with(self, obj):
"""Returns True if dataset/selection is mappable with this plot.
"""
print "is_mappable_with"
if isinstance(obj, fluents.dataset.Dataset):
if self.current_dim in obj.get_dim_name() \
and obj.asarray().shape[0] == self.xaxis_data.shape[0]:
if self.current_dim in obj.get_dim_name():
print "is_mappable_with: True"
return True
elif isinstance(obj, fluents.dataset.Selection):
if self.current_dim in obj.get_dim_name():
print "Selection is mappable"
print "is_mappable_with: True"
return True
else:
print "is_mappable_with: False"
return False
def _update_color_from_dataset(self, data):
"""Updates the facecolors from a dataset.
"""
print "_update_color_from_dataset"
array = data.asarray()
#only support for 2d-arrays:
try:
m, n = array.shape
except:
raise ValueError, "No support for more than 2 dimensions."
# is dataset a vector or matrix?
if not n==1:
# we have a category dataset
if isinstance(data, fluents.dataset.CategoryDataset):
map_vec = scipy.dot(array, scipy.diag(scipy.arange(n))).sum(1)
vec = dot(array, diag(arange(n))).sum(1)
else:
map_vec = array.sum(1)
vec = array.sum(1)
else:
map_vec = array.ravel()
vec = array.ravel()
identifiers = self.dataset_1.get_identifiers(self.current_dim, sorted=True)
indices = data.get_indices(self.current_dim, identifiers)
existing_ids = data.existing_identifiers(self.current_dim, identifiers)
v = vec[indices]
vec_min = min(vec[vec > -scipy.inf])
vec_max = max(vec[vec < scipy.inf])
v[v==scipy.inf] = vec_max
v[v==-scipy.inf] = vec_min
indices = self.dataset_1.get_indices(self.current_dim, existing_ids)
map_vec = vec_min*scipy.ones(len(identifiers))
map_vec[indices] = v
# update facecolors
self.sc.set_array(map_vec)
self.sc.set_clim(map_vec.min(), map_vec.max())
self.sc.set_clim(vec_min, vec_max)
self.sc.update_scalarmappable() #sets facecolors from array
self.canvas.draw()

View File

@ -726,8 +726,8 @@ class DagPlot(plots.Plot):
nodes = ds.existing_identifiers(self.current_dim, self.nodes)
v = vec.take(indices, 0)
vec_min = min(v[v > -inf])
vec_max = max(v[v < inf])
vec_min = min(vec[vec > -inf])
vec_max = max(vec[vec < inf])
v[v==inf] = vec_max
v[v==-inf] = vec_min
@ -739,7 +739,7 @@ class DagPlot(plots.Plot):
# update facecolors
self.node_collection.set_array(map_vec)
self.node_collection.set_clim(map_vec.min(), map_vec.max())
self.node_collection.set_clim(vec_min, vec_max)
self.node_collection.update_scalarmappable() #sets facecolors from array
self.canvas.draw()