import pygtk import gtk import matplotlib from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas 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 import scipy import logger class Plot (gtk.Frame): def __init__(self): gtk.Frame.__init__(self) self.canvas = None self.mark_active(False) self.connect('button_press_event', self.on_button_press) def on_button_press(self, *rest): logger.log('debug', 'button pressed in plot') self.mark_active(True) def get_toolbar(self, window): self.toolbar = NavigationToolbar(self.canvas, window) self.toolbar.set_property('show-arrow', False) return self.toolbar def mark_active(self, active): if active: self.set_shadow_type(gtk.SHADOW_IN) else: self.set_shadow_type(gtk.SHADOW_ETCHED_IN) class EmptyPlot (Plot): def __init__(self): Plot.__init__(self) label = gtk.Label('No plot') label.show() self.add(label) def get_toolbar(self, window): return None class SinePlot (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) s = sin(2*pi*t) ax.plot(t,s) self.canvas = FigureCanvas(fig) self.add(self.canvas) self.canvas.show() 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.canvas = FigureCanvas(fig) self.add(self.canvas) self.canvas.show()