From 56dac31529cc505d30ea73d1411b7b5797d9724d Mon Sep 17 00:00:00 2001 From: flatberg Date: Wed, 19 Apr 2006 18:25:44 +0000 Subject: [PATCH] Updated plots to demonstrate current selection update --- fluent | 4 ++++ system/navigator.py | 6 +++++ system/plots.py | 55 +++++++++++++++++++++++++++++---------------- system/project.py | 10 ++++----- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/fluent b/fluent index aae2693..63d4d60 100755 --- a/fluent +++ b/fluent @@ -88,6 +88,10 @@ class FluentApp: plot2 = plots.ScatterPlot() plot2.show() + + plot3 = plots.ScatterPlot() + plot3.show() + # pt.set_child(plot, 0, 1) # Set up plot toolbar dock = self.widget_tree.get_widget('plot_toolbar_dock') diff --git a/system/navigator.py b/system/navigator.py index 2eda05f..ddc0289 100644 --- a/system/navigator.py +++ b/system/navigator.py @@ -16,6 +16,12 @@ class NavigatorStore (gtk.TreeStore): self.set_value(iter, 0, ('Scatter Plot')) self.set_value(iter, 1, (plots.ScatterPlot())) + iter = self.append(None) + self.set_value(iter, 0, ('Scatter Plot 2')) + self.set_value(iter, 1, (plots.ScatterPlot())) + + + def plot_at(self, path): iter = self.get_iter(path) plot = self.get_value(iter, 1) diff --git a/system/plots.py b/system/plots.py index a59d257..a6c5de2 100644 --- a/system/plots.py +++ b/system/plots.py @@ -1,19 +1,17 @@ +import logger import pygtk import gtk import matplotlib +import scipy import project from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas from matplotlib.axes import Subplot from matplotlib.figure import Figure from matplotlib.numerix import arange, sin, pi from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar - from matplotlib.widgets import RectangleSelector -import scipy -import logger -import project class MainView (gtk.Notebook): def __init__(self): @@ -186,7 +184,7 @@ class Plot (gtk.Frame): self.set_shadow_type(gtk.SHADOW_OUT) def update_selection(self,project): - self.selection_object = project.get_selection() + pass class EmptyView (Plot): def __init__(self): @@ -235,21 +233,27 @@ class ScatterPlot (Plot): Plot.__init__(self) fig = Figure(figsize=(5,4), dpi=72) self.ax = ax = fig.add_subplot(111) - self.x_dataset = project.c_p.datasets[0] + + # testing testing + self.c_p = project.c_p + self.x_dataset = self.c_p.datasets[0] x = self.x_dataset._data - self.xaxis_data = xaxis_data = x[:,0] + self.xaxis_data = xaxis_data = x[:,0] + scipy.randn(scipy.shape(x)[0]) self.yaxis_data = yaxis_data = x[:,1] + self.current_dim = self.x_dataset._dim_names[0] ax.plot(xaxis_data,yaxis_data,'og') + ### + self.canvas = FigureCanvas(fig) self.add(self.canvas) - rectprops = dict(facecolor='blue', edgecolor = 'black', - alpha=0.2, fill=True) - sel = RectangleSelector(ax, self.line_select_callback, + rectprops = dict(facecolor='gray', edgecolor = 'black', + alpha=0.2, fill=True) #cool + sel = RectangleSelector(ax, self.rectangle_select_callback, drawtype='box',useblit=True,rectprops=rectprops) self.canvas.show() - def line_select_callback(self,event1, event2): + def rectangle_select_callback(self,event1, event2): 'event1 and event2 are the press and release events' x1, y1 = event1.xdata, event1.ydata x2, y2 = event2.xdata, event2.ydata @@ -259,28 +263,41 @@ class ScatterPlot (Plot): ydata = self.yaxis_data xdata = self.xaxis_data if x1>x2: + logger.log('debug','Selection x_start bigger than x_end') if y1x2) & (ydata>y1) & (ydatax2) & (ydatay2)) else: + logger.log('debug','Selection x_start less than x_end') if y1x2) & (xdatay1) & (ydatax1) & (xdatay1) & (ydatax2) & (xdatay2)) + logger.log('debug','Selection y_start bigger than y_end') + index =scipy.nonzero((xdata>x1) & (xdatay2)) + if len(index)==0: logger.log('debug','No points selected!') else: logger.log('debug','Selected:\n%s'%index) ids = self.x_dataset.extract_id_from_index('samples',index) + #update selection object + self.c_p.set_selection(self.c_p.sel_obj,self.current_dim,ids) logger.log('debug','Selected identifiers:\n%s'%ids) - xdata_new = scipy.take(xdata,index) - ydata_new = scipy.take(ydata,index) - # self.ax.plot(xdata,ydata,'og') - self.ax.plot(xdata_new,ydata_new,'or') - self.canvas.draw() - + + def update_selection(self,project): + curr_sel = project.get_selection(self.c_p.sel_obj) + ids = curr_sel[self.current_dim] + index = self.x_dataset.extract_index_from_id(self.current_dim,ids) + xdata_new = scipy.take(self.xaxis_data,index) + ydata_new = scipy.take(self.yaxis_data,index) + self.ax.plot(xdata_new,ydata_new,'or') + self.canvas.draw() + def get_toolbar(self, window): self.toolbar = NavigationToolbar(self.canvas, window) self.toolbar.set_property('show-arrow', False) diff --git a/system/project.py b/system/project.py index ce97648..792b207 100644 --- a/system/project.py +++ b/system/project.py @@ -24,9 +24,9 @@ class Project: def notify(self, modifier=None): """Notifies observers that selection is updated""" - for observer in self.selection_observers: + for observer in self._selection_observers: if modifier != observer: - observer.update(self) + observer.update_selection(self) def set_selection(self,sel_obj,dim_name,selection): """Sets selection and notifies observers""" @@ -48,7 +48,7 @@ class Project: def suggest_dim_name(self,dim_name): """Creates an arbitrary unique name for a new dimension.""" - if dim_name in self.dim_names: + while dim_name in self.dim_names: dim_name = dim_name + "_t" return dim_name @@ -61,8 +61,8 @@ def_list = [ ['samples',[]], ['genes',['a','b','c']] ] test_data = dataset.Dataset(x,def_list) c_p.add_dataset(test_data) -y = scipy.rand(2,2) -def_list = [ ['samples',['1','2']], ['yclasses',['C','N']] ] +y = scipy.rand(2000,2) +def_list = [ ['samples',[]], ['yclasses',['C','N']] ] test_data = dataset.Dataset(y,def_list) c_p.add_dataset(test_data)