From 1d48bd85c58fdae422da4f5becc189de85843eed Mon Sep 17 00:00:00 2001 From: flatberg Date: Tue, 18 Apr 2006 09:19:59 +0000 Subject: [PATCH] added scatter --- fluent | 6 ++++-- system/navigator.py | 4 ++-- system/plots.py | 33 +++++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/fluent b/fluent index 086ca15..5a8ad3d 100755 --- a/fluent +++ b/fluent @@ -80,13 +80,15 @@ class FluentApp: wf_menu.show() wf_box.pack_end(wf_menu) - # Set up plot + # Set up plots pt = self.widget_tree.get_widget('small_view') plot = plots.SinePlot() plot.show() plot.mark_active(True) -# pt.set_child(plot, 0, 1) + plot2 = plots.ScatterPlot() + plot2.show() + # pt.set_child(plot, 0, 1) # Set up plot toolbar dock = self.widget_tree.get_widget('plot_toolbar_dock') dock.add(plot.get_toolbar(self.app)) diff --git a/system/navigator.py b/system/navigator.py index d611016..2eda05f 100644 --- a/system/navigator.py +++ b/system/navigator.py @@ -13,8 +13,8 @@ class NavigatorStore (gtk.TreeStore): self.set_value(iter, 1, (plots.SinePlot())) iter = self.append(None) - self.set_value(iter, 0, ('Sine Plot 1')) - self.set_value(iter, 1, (plots.EmptyView())) + self.set_value(iter, 0, ('Scatter Plot')) + self.set_value(iter, 1, (plots.ScatterPlot())) def plot_at(self, path): iter = self.get_iter(path) diff --git a/system/plots.py b/system/plots.py index 9fe6d8b..8b216da 100644 --- a/system/plots.py +++ b/system/plots.py @@ -7,6 +7,9 @@ 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 @@ -224,16 +227,38 @@ class ScatterPlot (Plot): def __init__(self): Plot.__init__(self) fig = Figure(figsize=(5,4), dpi=72) - ax = fig.add_subplot(111) - t = arange(0.0, 3.0, 0.01) - a = scipy.randn(200, 300) - fig.plot(a) + self.ax = ax = fig.add_subplot(111) + N = 200 + self.a = a = scipy.randn(N) + self.b = b = scipy.randn(N) + ax.plot(a,b,'og') self.canvas = FigureCanvas(fig) self.add(self.canvas) + sel = RectangleSelector(ax, self.line_select_callback, + drawtype='box',useblit=True) + 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 + x2, y2 = event2.xdata, event2.ydata + logger.log('debug', "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2)) + logger.log('debug',"The button you used were:%s, %s "%(event1.button, event2.button)) + # get all points within x1, y1, x2, y2 + ydata = self.b + xdata = self.a + index =scipy.nonzero((xdatax1) & (ydatay2)) + 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) self.toolbar.set_property('show-arrow', False) return self.toolbar +