added scatter
This commit is contained in:
parent
a0d2c0d16d
commit
1d48bd85c5
6
fluent
6
fluent
|
@ -80,13 +80,15 @@ class FluentApp:
|
||||||
wf_menu.show()
|
wf_menu.show()
|
||||||
wf_box.pack_end(wf_menu)
|
wf_box.pack_end(wf_menu)
|
||||||
|
|
||||||
# Set up plot
|
# Set up plots
|
||||||
pt = self.widget_tree.get_widget('small_view')
|
pt = self.widget_tree.get_widget('small_view')
|
||||||
plot = plots.SinePlot()
|
plot = plots.SinePlot()
|
||||||
plot.show()
|
plot.show()
|
||||||
plot.mark_active(True)
|
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
|
# Set up plot toolbar
|
||||||
dock = self.widget_tree.get_widget('plot_toolbar_dock')
|
dock = self.widget_tree.get_widget('plot_toolbar_dock')
|
||||||
dock.add(plot.get_toolbar(self.app))
|
dock.add(plot.get_toolbar(self.app))
|
||||||
|
|
|
@ -13,8 +13,8 @@ class NavigatorStore (gtk.TreeStore):
|
||||||
self.set_value(iter, 1, (plots.SinePlot()))
|
self.set_value(iter, 1, (plots.SinePlot()))
|
||||||
|
|
||||||
iter = self.append(None)
|
iter = self.append(None)
|
||||||
self.set_value(iter, 0, ('Sine Plot 1'))
|
self.set_value(iter, 0, ('Scatter Plot'))
|
||||||
self.set_value(iter, 1, (plots.EmptyView()))
|
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)
|
||||||
|
|
|
@ -7,6 +7,9 @@ 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
|
||||||
|
|
||||||
import scipy
|
import scipy
|
||||||
import logger
|
import logger
|
||||||
|
|
||||||
|
@ -224,16 +227,38 @@ class ScatterPlot (Plot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Plot.__init__(self)
|
Plot.__init__(self)
|
||||||
fig = Figure(figsize=(5,4), dpi=72)
|
fig = Figure(figsize=(5,4), dpi=72)
|
||||||
ax = fig.add_subplot(111)
|
self.ax = ax = fig.add_subplot(111)
|
||||||
t = arange(0.0, 3.0, 0.01)
|
N = 200
|
||||||
a = scipy.randn(200, 300)
|
self.a = a = scipy.randn(N)
|
||||||
fig.plot(a)
|
self.b = b = scipy.randn(N)
|
||||||
|
ax.plot(a,b,'og')
|
||||||
self.canvas = FigureCanvas(fig)
|
self.canvas = FigureCanvas(fig)
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
|
sel = RectangleSelector(ax, self.line_select_callback,
|
||||||
|
drawtype='box',useblit=True)
|
||||||
|
|
||||||
self.canvas.show()
|
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((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()
|
||||||
|
|
||||||
def get_toolbar(self, window):
|
def get_toolbar(self, window):
|
||||||
self.toolbar = NavigationToolbar(self.canvas, window)
|
self.toolbar = NavigationToolbar(self.canvas, window)
|
||||||
self.toolbar.set_property('show-arrow', False)
|
self.toolbar.set_property('show-arrow', False)
|
||||||
return self.toolbar
|
return self.toolbar
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue