mainly play in plots

This commit is contained in:
2006-04-18 14:25:46 +00:00
parent 1d48bd85c5
commit a8937ededb
4 changed files with 64 additions and 21 deletions

View File

@@ -2,6 +2,7 @@
import pygtk
import gtk
import matplotlib
import project
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.axes import Subplot
from matplotlib.figure import Figure
@@ -12,6 +13,7 @@ from matplotlib.widgets import RectangleSelector
import scipy
import logger
import project
class MainView (gtk.Notebook):
def __init__(self):
@@ -167,7 +169,9 @@ class Plot (gtk.Frame):
gtk.Frame.__init__(self)
self.mark_active(False)
self.connect('button_press_event', self.on_button_press)
self.sel_obj = None
project.c_p.attach(self)
def on_button_press(self, *rest):
logger.log('debug', 'button pressed in plot')
self.mark_active(True)
@@ -180,7 +184,10 @@ class Plot (gtk.Frame):
self.set_shadow_type(gtk.SHADOW_IN)
else:
self.set_shadow_type(gtk.SHADOW_OUT)
def update_selection(self,project):
self.selection_object = project.get_selection()
class EmptyView (Plot):
def __init__(self):
Plot.__init__(self)
@@ -228,18 +235,20 @@ class ScatterPlot (Plot):
Plot.__init__(self)
fig = Figure(figsize=(5,4), dpi=72)
self.ax = ax = fig.add_subplot(111)
N = 200
self.a = a = scipy.randn(N)
self.b = b = scipy.randn(N)
self.x_dataset = project.c_p.datasets[0]
x = self.x_dataset._data
self.a = a = x[:,0]
self.b = b = x[:,1]
ax.plot(a,b,'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,
drawtype='box',useblit=True)
drawtype='box',useblit=True,rectprops=rectprops)
self.canvas.show()
def line_select_callback(self,event1, event2):
'event1 and event2 are the press and release events'
x1, y1 = event1.xdata, event1.ydata
@@ -250,11 +259,17 @@ class ScatterPlot (Plot):
ydata = self.b
xdata = self.a
index =scipy.nonzero((xdata<x2) & (xdata>x1) & (ydata<y1) & (ydata>y2))
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()
if len(index)==0:
logger.log('debug','No points selected!')
else:
logger.log('debug','Selected:\n%s'%index)
ids = self.x_dataset.index_to_id('samples',index)
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 get_toolbar(self, window):
self.toolbar = NavigationToolbar(self.canvas, window)