Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

added a logger for constructor calls

This commit is contained in:
Arnar Flatberg 2007-03-14 16:27:23 +00:00
parent 212da78933
commit 818dc0b2b0
1 changed files with 26 additions and 11 deletions

View File

@ -2,6 +2,7 @@ import pygtk
import gobject import gobject
import gtk import gtk
import matplotlib
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
from matplotlib.nxutils import points_inside_poly from matplotlib.nxutils import points_inside_poly
from matplotlib.figure import Figure from matplotlib.figure import Figure
@ -17,8 +18,15 @@ import fluents
import logger import logger
import view import view
def plotlogger(func, name=None):
def wrapped(parent, *args, **kw):
parent.__args = args
parent.__kw = kw
return func(parent, *args, **kw)
return wrapped
class Plot (view.View):
class Plot(view.View):
def __init__(self, title): def __init__(self, title):
view.View.__init__(self, title) view.View.__init__(self, title)
logger.log('debug', 'plot %s init' %title) logger.log('debug', 'plot %s init' %title)
@ -132,6 +140,7 @@ class LineViewPlot(Plot):
fixme: slow fixme: slow
""" """
@plotlogger
def __init__(self, dataset, major_axis=1, minor_axis=None, name="Line view"): def __init__(self, dataset, major_axis=1, minor_axis=None, name="Line view"):
Plot.__init__(self, name) Plot.__init__(self, name)
self.dataset = dataset self.dataset = dataset
@ -233,7 +242,7 @@ class LineViewPlot(Plot):
class ScatterMarkerPlot(Plot): class ScatterMarkerPlot(Plot):
"""The ScatterMarkerPlot is faster than regular scatterplot, but """The ScatterMarkerPlot is faster than regular scatterplot, but
has no color and size options.""" has no color and size options."""
@plotlogger
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, def __init__(self, dataset_1, dataset_2, id_dim, sel_dim,
id_1, id_2, s=6, name="Scatter plot"): id_1, id_2, s=6, name="Scatter plot"):
Plot.__init__(self, name) Plot.__init__(self, name)
@ -306,12 +315,14 @@ class ScatterMarkerPlot(Plot):
class ScatterPlot(Plot): class ScatterPlot(Plot):
"""The ScatterPlot is slower than scattermarker, but has size option.""" """The ScatterPlot is slower than scattermarker, but has size option."""
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2, c='b', s=30, sel_dim_2=None, name="Scatter plot"): @plotlogger
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2, c='b', s=30, sel_dim_2=None, name="Scatter plot", **kw):
Plot.__init__(self, name) Plot.__init__(self, name)
self.dataset_1 = dataset_1 self.dataset_1 = dataset_1
self.s = s self.s = s
self.c = c self.c = c
self.kw = kw
self.current_dim = id_dim self.current_dim = id_dim
x_index = dataset_1[sel_dim][id_1] x_index = dataset_1[sel_dim][id_1]
@ -355,7 +366,8 @@ class ScatterPlot(Plot):
def init_draw(self): def init_draw(self):
lw = scipy.zeros(self.xaxis_data.shape) lw = scipy.zeros(self.xaxis_data.shape)
self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data, self.sc = self.axes.scatter(self.xaxis_data, self.yaxis_data,
s=self.s, c=self.c, linewidth=lw, zorder=3) s=self.s, c=self.c, linewidth=lw,
zorder=3, **self.kw)
self.axes.axhline(0, color='k', lw=1., zorder=1) self.axes.axhline(0, color='k', lw=1., zorder=1)
self.axes.axvline(0, color='k', lw=1., zorder=1) self.axes.axvline(0, color='k', lw=1., zorder=1)
self.selection_collection = self.axes.scatter(self.xaxis_data, self.selection_collection = self.axes.scatter(self.xaxis_data,
@ -449,6 +461,7 @@ class ScatterPlot(Plot):
class ImagePlot(Plot): class ImagePlot(Plot):
@plotlogger
def __init__(self, dataset, **kw): def __init__(self, dataset, **kw):
Plot.__init__(self, kw.get('name', 'Image Plot')) Plot.__init__(self, kw.get('name', 'Image Plot'))
self.dataset = dataset self.dataset = dataset
@ -469,7 +482,7 @@ class HistogramPlot(Plot):
If dataset is 1-dim the current_dim is set and selections may If dataset is 1-dim the current_dim is set and selections may
be performed. For dataset> 1.dim the histogram is over all values be performed. For dataset> 1.dim the histogram is over all values
and selections are not defined,""" and selections are not defined,"""
@plotlogger
def __init__(self, dataset, **kw): def __init__(self, dataset, **kw):
Plot.__init__(self, kw['name']) Plot.__init__(self, kw['name'])
self.dataset = dataset self.dataset = dataset
@ -556,6 +569,7 @@ class BarPlot(Plot):
Ordinary bar plot for (column) vectors. Ordinary bar plot for (column) vectors.
For matrices there is one color for each row. For matrices there is one color for each row.
""" """
@plotlogger
def __init__(self, dataset, **kw): def __init__(self, dataset, **kw):
Plot.__init__(self, kw.get('name', 'Bar Plot')) Plot.__init__(self, kw.get('name', 'Bar Plot'))
self.dataset = dataset self.dataset = dataset
@ -564,8 +578,7 @@ class BarPlot(Plot):
self.axes.grid(False) self.axes.grid(False)
n, m = dataset.shape n, m = dataset.shape
if m>1: if m>1:
sm = matplotlib.cm.ScalarMappable() clrs = matplotlib.cm.ScalarMappable().to_rgba(range(n))
clrs = sm.to_rgba(range(n))
for i, row in enumerate(dataset.asarray()): for i, row in enumerate(dataset.asarray()):
left = scipy.arange(i+1, m*n+1, n) left = scipy.arange(i+1, m*n+1, n)
height = row height = row
@ -584,6 +597,7 @@ class BarPlot(Plot):
class NetworkPlot(Plot): class NetworkPlot(Plot):
@plotlogger
def __init__(self, dataset, pos=None, nodecolor='b', nodesize=40, def __init__(self, dataset, pos=None, nodecolor='b', nodesize=40,
prog='neato', with_labels=False, name='Network Plot'): prog='neato', with_labels=False, name='Network Plot'):
@ -606,9 +620,9 @@ class NetworkPlot(Plot):
# Initial draw # Initial draw
self.default_props = {'nodesize' : 50, self.default_props = {'nodesize' : 50,
'nodecolor' : 'gray', 'nodecolor' : 'blue',
'edge_color' : (.5, .5, .5, 1), 'edge_color' : 'gray',
'edge_color_selected' : (1,0,0,1)} 'edge_color_selected' : 'red'}
self.node_collection = None self.node_collection = None
self.edge_collection = None self.edge_collection = None
self.node_labels = None self.node_labels = None
@ -634,7 +648,7 @@ class NetworkPlot(Plot):
self._pos, self._pos,
ax=self.axes, ax=self.axes,
edge_color=edge_color) edge_color=edge_color)
# edge color rgba-array # edge color rgba-arrays
self._edge_color_rgba = scipy.repmat(ColorConverter().to_rgba(edge_color), self._edge_color_rgba = scipy.repmat(ColorConverter().to_rgba(edge_color),
self.graph.number_of_edges(),1) self.graph.number_of_edges(),1)
self._edge_color_selected = ColorConverter().to_rgba(self.default_props['edge_color_selected']) self._edge_color_selected = ColorConverter().to_rgba(self.default_props['edge_color_selected'])
@ -693,6 +707,7 @@ class NetworkPlot(Plot):
class VennPlot(Plot): class VennPlot(Plot):
@plotlogger
def __init__(self, name="Venn diagram"): def __init__(self, name="Venn diagram"):
Plot.__init__(self, name) Plot.__init__(self, name)