Updated plots to demonstrate current selection update
This commit is contained in:
parent
1091bea0e9
commit
56dac31529
4
fluent
4
fluent
|
@ -88,6 +88,10 @@ class FluentApp:
|
||||||
|
|
||||||
plot2 = plots.ScatterPlot()
|
plot2 = plots.ScatterPlot()
|
||||||
plot2.show()
|
plot2.show()
|
||||||
|
|
||||||
|
plot3 = plots.ScatterPlot()
|
||||||
|
plot3.show()
|
||||||
|
|
||||||
# pt.set_child(plot, 0, 1)
|
# pt.set_child(plot, 0, 1)
|
||||||
# Set up plot toolbar
|
# Set up plot toolbar
|
||||||
dock = self.widget_tree.get_widget('plot_toolbar_dock')
|
dock = self.widget_tree.get_widget('plot_toolbar_dock')
|
||||||
|
|
|
@ -16,6 +16,12 @@ class NavigatorStore (gtk.TreeStore):
|
||||||
self.set_value(iter, 0, ('Scatter Plot'))
|
self.set_value(iter, 0, ('Scatter Plot'))
|
||||||
self.set_value(iter, 1, (plots.ScatterPlot()))
|
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):
|
def plot_at(self, path):
|
||||||
iter = self.get_iter(path)
|
iter = self.get_iter(path)
|
||||||
plot = self.get_value(iter, 1)
|
plot = self.get_value(iter, 1)
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
|
|
||||||
|
import logger
|
||||||
import pygtk
|
import pygtk
|
||||||
import gtk
|
import gtk
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
import scipy
|
||||||
import project
|
import project
|
||||||
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
|
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
|
||||||
from matplotlib.axes import Subplot
|
from matplotlib.axes import Subplot
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
from matplotlib.numerix import arange, sin, pi
|
from matplotlib.numerix import arange, sin, pi
|
||||||
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
|
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
|
||||||
|
|
||||||
from matplotlib.widgets import RectangleSelector
|
from matplotlib.widgets import RectangleSelector
|
||||||
|
|
||||||
import scipy
|
|
||||||
import logger
|
|
||||||
import project
|
|
||||||
|
|
||||||
class MainView (gtk.Notebook):
|
class MainView (gtk.Notebook):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -186,7 +184,7 @@ class Plot (gtk.Frame):
|
||||||
self.set_shadow_type(gtk.SHADOW_OUT)
|
self.set_shadow_type(gtk.SHADOW_OUT)
|
||||||
|
|
||||||
def update_selection(self,project):
|
def update_selection(self,project):
|
||||||
self.selection_object = project.get_selection()
|
pass
|
||||||
|
|
||||||
class EmptyView (Plot):
|
class EmptyView (Plot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -235,21 +233,27 @@ class ScatterPlot (Plot):
|
||||||
Plot.__init__(self)
|
Plot.__init__(self)
|
||||||
fig = Figure(figsize=(5,4), dpi=72)
|
fig = Figure(figsize=(5,4), dpi=72)
|
||||||
self.ax = ax = fig.add_subplot(111)
|
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
|
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.yaxis_data = yaxis_data = x[:,1]
|
||||||
|
self.current_dim = self.x_dataset._dim_names[0]
|
||||||
ax.plot(xaxis_data,yaxis_data,'og')
|
ax.plot(xaxis_data,yaxis_data,'og')
|
||||||
|
###
|
||||||
|
|
||||||
self.canvas = FigureCanvas(fig)
|
self.canvas = FigureCanvas(fig)
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
rectprops = dict(facecolor='blue', edgecolor = 'black',
|
rectprops = dict(facecolor='gray', edgecolor = 'black',
|
||||||
alpha=0.2, fill=True)
|
alpha=0.2, fill=True) #cool
|
||||||
sel = RectangleSelector(ax, self.line_select_callback,
|
sel = RectangleSelector(ax, self.rectangle_select_callback,
|
||||||
drawtype='box',useblit=True,rectprops=rectprops)
|
drawtype='box',useblit=True,rectprops=rectprops)
|
||||||
|
|
||||||
self.canvas.show()
|
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'
|
'event1 and event2 are the press and release events'
|
||||||
x1, y1 = event1.xdata, event1.ydata
|
x1, y1 = event1.xdata, event1.ydata
|
||||||
x2, y2 = event2.xdata, event2.ydata
|
x2, y2 = event2.xdata, event2.ydata
|
||||||
|
@ -259,25 +263,38 @@ class ScatterPlot (Plot):
|
||||||
ydata = self.yaxis_data
|
ydata = self.yaxis_data
|
||||||
xdata = self.xaxis_data
|
xdata = self.xaxis_data
|
||||||
if x1>x2:
|
if x1>x2:
|
||||||
|
logger.log('debug','Selection x_start bigger than x_end')
|
||||||
if y1<y2:
|
if y1<y2:
|
||||||
|
logger.log('debug','Selection y_start less than y_end')
|
||||||
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata>y1) & (ydata<y2))
|
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata>y1) & (ydata<y2))
|
||||||
else:
|
else:
|
||||||
|
logger.log('debug','Selection y_start larger than y_end')
|
||||||
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata<y1) & (ydata>y2))
|
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata<y1) & (ydata>y2))
|
||||||
else:
|
else:
|
||||||
|
logger.log('debug','Selection x_start less than x_end')
|
||||||
if y1<y2:
|
if y1<y2:
|
||||||
index =scipy.nonzero((xdata>x2) & (xdata<x1) & (ydata>y1) & (ydata<y2))
|
logger.log('debug','Selection y_start less than y_end')
|
||||||
|
index =scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))
|
||||||
else:
|
else:
|
||||||
index =scipy.nonzero((xdata>x2) & (xdata<x1) & (ydata<y1) & (ydata>y2))
|
logger.log('debug','Selection y_start bigger than y_end')
|
||||||
|
index =scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata<y1) & (ydata>y2))
|
||||||
|
|
||||||
|
|
||||||
if len(index)==0:
|
if len(index)==0:
|
||||||
logger.log('debug','No points selected!')
|
logger.log('debug','No points selected!')
|
||||||
else:
|
else:
|
||||||
logger.log('debug','Selected:\n%s'%index)
|
logger.log('debug','Selected:\n%s'%index)
|
||||||
ids = self.x_dataset.extract_id_from_index('samples',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)
|
logger.log('debug','Selected identifiers:\n%s'%ids)
|
||||||
xdata_new = scipy.take(xdata,index)
|
|
||||||
ydata_new = scipy.take(ydata,index)
|
def update_selection(self,project):
|
||||||
# self.ax.plot(xdata,ydata,'og')
|
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.ax.plot(xdata_new,ydata_new,'or')
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ class Project:
|
||||||
|
|
||||||
def notify(self, modifier=None):
|
def notify(self, modifier=None):
|
||||||
"""Notifies observers that selection is updated"""
|
"""Notifies observers that selection is updated"""
|
||||||
for observer in self.selection_observers:
|
for observer in self._selection_observers:
|
||||||
if modifier != observer:
|
if modifier != observer:
|
||||||
observer.update(self)
|
observer.update_selection(self)
|
||||||
|
|
||||||
def set_selection(self,sel_obj,dim_name,selection):
|
def set_selection(self,sel_obj,dim_name,selection):
|
||||||
"""Sets selection and notifies observers"""
|
"""Sets selection and notifies observers"""
|
||||||
|
@ -48,7 +48,7 @@ class Project:
|
||||||
|
|
||||||
def suggest_dim_name(self,dim_name):
|
def suggest_dim_name(self,dim_name):
|
||||||
"""Creates an arbitrary unique name for a new dimension."""
|
"""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"
|
dim_name = dim_name + "_t"
|
||||||
return dim_name
|
return dim_name
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ def_list = [ ['samples',[]], ['genes',['a','b','c']] ]
|
||||||
test_data = dataset.Dataset(x,def_list)
|
test_data = dataset.Dataset(x,def_list)
|
||||||
c_p.add_dataset(test_data)
|
c_p.add_dataset(test_data)
|
||||||
|
|
||||||
y = scipy.rand(2,2)
|
y = scipy.rand(2000,2)
|
||||||
def_list = [ ['samples',['1','2']], ['yclasses',['C','N']] ]
|
def_list = [ ['samples',[]], ['yclasses',['C','N']] ]
|
||||||
test_data = dataset.Dataset(y,def_list)
|
test_data = dataset.Dataset(y,def_list)
|
||||||
c_p.add_dataset(test_data)
|
c_p.add_dataset(test_data)
|
||||||
|
|
||||||
|
|
Reference in New Issue