Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/system/plots.py

72 lines
1.9 KiB
Python
Raw Normal View History

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()