Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

updated Lineview and Plot

This commit is contained in:
Arnar Flatberg 2006-08-14 15:01:34 +00:00
parent fc8b2e601f
commit a5c5987fc3
1 changed files with 23 additions and 19 deletions

View File

@ -233,7 +233,11 @@ class Plot (gtk.Frame):
self.title = title
self.selection_listener = None
self.set_shadow_type(gtk.SHADOW_NONE)
self._background = None
self.canvas = None
self.fig = Figure(figsize=(5,4), dpi=72)
self.canvas = FigureCanvas(self.fig)
self.fig.set_facecolor('white')
def get_title(self):
return self.title
@ -252,7 +256,6 @@ class Plot (gtk.Frame):
def get_toolbar(self):
return None
class EmptyView (Plot):
def __init__(self):
Plot.__init__(self, 'Empty view')
@ -332,6 +335,7 @@ class NavToolbar(NavigationToolbar2):
self._select_callback(lastx, lasty, x, y)
self._xypress = None
self.push_current()
self.release(event)
def mouse_move(self, event):
@ -393,9 +397,8 @@ class LineViewPlot(Plot):
self._data = dataset.asarray()
self.dataset = dataset
Plot.__init__(self, name)
fig = Figure(figsize=(5,4), dpi=72)
self.canvas = FigureCanvas(fig)
self.ax = fig.add_subplot(111)
self.ax = self.fig.add_subplot(111)
self.ax.set_title(self.get_title())
self.current_dim = self.dataset.get_dim_name(major_axis)
if len(self._data.shape)==2 and not minor_axis:
minor_axis = major_axis-1
@ -404,10 +407,8 @@ class LineViewPlot(Plot):
x_axis = scipy.arrayrange(self._data.shape[minor_axis])
for i in range(self._data.shape[major_axis]):
yi = scipy.take(self._data,[i],axis=major_axis)
l, = self.ax.plot(x_axis,yi,animated=True)
l, = self.ax.plot(x_axis,yi,'k',alpha=.05,animated=True)
self.line_collection[i] = l
# store clean state
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
self.add(self.canvas)
self.canvas.show()
@ -415,18 +416,27 @@ class LineViewPlot(Plot):
# We use a regular toolbar as we don't need selections
self._toolbar = NavigationToolbar2(self.canvas, None)
self._toolbar.set_property('show-arrow', False)
self.canvas.mpl_connect('resize_event',self.clear_background)
def get_toolbar(self):
return self._toolbar
def clear_background(self,event):
self._background = None
def selection_changed(self, selection):
ids = selection[self.current_dim] # current identifiers
index = self.dataset.get_indices(self.current_dim, ids)
if self._background is not None:
self.canvas.restore_region(self._background)
if self._background is None:
print "background needs copy"
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
print self.ax.bbox.get_bounds()
self.canvas.restore_region(self._background)
if index:
for i in index:
self.line_collection[i].set_visible(True)
self.line_collection[i].set_color('r')
self.line_collection[i].set_alpha(1.0)
self.ax.draw_artist(self.line_collection[i])
self.canvas.blit()
@ -435,8 +445,7 @@ class ScatterMarkerPlot(Plot):
has no color and size options."""
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2, name="Scatter plot"):
Plot.__init__(self, name)
fig = Figure(figsize=(5,4), dpi=72)
self.ax = ax = fig.add_subplot(111)
self.ax = ax = self.fig.add_subplot(111)
self.current_dim = id_dim
self.dataset_1 = dataset_1
@ -451,8 +460,6 @@ has no color and size options."""
ax.set_ylabel("%s - %s" % (sel_dim, id_2))
###
self.canvas = FigureCanvas(fig)
self.add(self.canvas)
self.canvas.show()
@ -531,15 +538,12 @@ class NetworkPlot(Plot):
if kw.has_key('node_color'):
kw.pop('node_color')
# FIXME: What is figsize?
self.fig = Figure(figsize=(5, 4), dpi=72)
self.ax = self.fig.add_subplot(111)
# FIXME: ax shouldn't be in kw at all
if kw.has_key('ax'):
kw.pop('ax')
# Add canvas and show
self.canvas = FigureCanvas(self.fig)
self.add(self.canvas)
self.canvas.show()