From 07477888bb06b88873bf08f9009fbedc418fc152 Mon Sep 17 00:00:00 2001 From: flatberg Date: Fri, 14 Dec 2007 15:43:35 +0000 Subject: [PATCH] Fixed colormap bug --- fluents/plots.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/fluents/plots.py b/fluents/plots.py index 426fc1c..efaff65 100644 --- a/fluents/plots.py +++ b/fluents/plots.py @@ -418,7 +418,7 @@ class ScatterPlot(Plot): sb_o.set_increments(1, 5) sb_o.connect('value_changed', self.set_ordinate) hbox = gtk.HBox() - gtk_label_a = gtk.Label("A:") + gtk_label_a = gtk.Label(" A:") gtk_label_o = gtk.Label(" O:") toolitem = gtk.ToolItem() toolitem.set_expand(False) @@ -530,28 +530,46 @@ class ScatterPlot(Plot): else: 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) + # corresponding indices of input data 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) + # use only values present in scatterplot 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 + ptp = abs(vec_max - 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) + map_vec = vec_max*scipy.ones(len(identifiers)) + # setting all present values to v + map_vec[indices] = v + # update facecolors self.sc.set_array(map_vec) self.sc.set_clim(vec_min, vec_max) 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"): - print "changing lut" - self.sc.cmap._lut[-1,:] = [.5,.5,.5,1] - self.sc.cmap._lut[0,:] = [.5,.5,.5,1] + #! 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] else: print "No lut present" self.canvas.draw()