Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Fixed colormap bug

This commit is contained in:
Arnar Flatberg 2007-12-14 15:43:35 +00:00
parent 5c2df5c163
commit 07477888bb
1 changed files with 28 additions and 10 deletions

View File

@ -530,28 +530,46 @@ class ScatterPlot(Plot):
else: else:
vec = array.ravel() vec = array.ravel()
# 1.) Set all ids present in plot but not in dataset to gray
# 2.) Set all ids which are inf/-inf/nan in dataset to gray
# ids of scatterplot
identifiers = self.dataset_1.get_identifiers(self.current_dim, sorted=True) identifiers = self.dataset_1.get_identifiers(self.current_dim, sorted=True)
# corresponding indices of input data
indices = data.get_indices(self.current_dim, identifiers) indices = data.get_indices(self.current_dim, identifiers)
# ids of scatterplot that is present in input data
existing_ids = data.existing_identifiers(self.current_dim, identifiers) existing_ids = data.existing_identifiers(self.current_dim, identifiers)
# use only values present in scatterplot
v = vec[indices] v = vec[indices]
vec_min = min(vec[vec > -scipy.inf]) vec_min = min(vec[vec > -scipy.inf])
vec_max = max(vec[vec < scipy.inf]) vec_max = max(vec[vec < scipy.inf])
v[v==scipy.inf] = vec_max ptp = abs(vec_max - vec_min)
v[v==-scipy.inf] = vec_min # set all infs equal to max value + delta
delta = 2.
v[v==scipy.inf] = vec_max + delta
v[v==-scipy.inf] = vec_max + delta
v[v==scipy.nan] = vec_max + delta
# get the indices of scatterplot ids present in input data
indices = self.dataset_1.get_indices(self.current_dim, existing_ids) indices = self.dataset_1.get_indices(self.current_dim, existing_ids)
map_vec = vec_min*scipy.ones(len(identifiers)) map_vec = vec_max*scipy.ones(len(identifiers))
# setting all present values to v
map_vec[indices] = v map_vec[indices] = v
# update facecolors # update facecolors
self.sc.set_array(map_vec) self.sc.set_array(map_vec)
self.sc.set_clim(vec_min, vec_max) self.sc.set_clim(vec_min, vec_max)
self.sc.update_scalarmappable() #sets facecolors from array self.sc.update_scalarmappable() #sets facecolors from array
# adjust max values so they get one (1) bin in lut
if hasattr(self.sc.cmap, "_lut"): if hasattr(self.sc.cmap, "_lut"):
print "changing lut" #! fixme this is just a hack, not even tested
lut_l = 1.*self.sc.cmap._lut.shape[0]
map_vec_range = map_vec.ptp()
delta_lut = map_vec_range/lut_l
map_vec[vec_max + delta] = vec_max + delta_lut/2.
self.sc.cmap._lut[-1,:] = [.5, .5, .5, 1] self.sc.cmap._lut[-1,:] = [.5, .5, .5, 1]
self.sc.cmap._lut[0,:] = [.5,.5,.5,1]
else: else:
print "No lut present" print "No lut present"
self.canvas.draw() self.canvas.draw()