Attachment 'mplwidget.py'
Download 1 import sys, os, random
2 from qt import *
3
4 import matplotlib
5 matplotlib.use('Agg')
6 import pylab
7
8 from matplotlib.numerix import arange, sin, pi
9
10 from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
11 from matplotlib.figure import Figure
12
13
14 class MatplotlibWidget(FigureCanvas):
15 """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
16 def __init__(self, parent=None, name=None, width=5, height=4, dpi=100, bgcolor=None):
17 self.parent = parent
18 if self.parent:
19 bgc = parent.backgroundBrush().color()
20 bgcolor = float(bgc.red())/255.0, float(bgc.green())/255.0, float(bgc.blue())/255.0
21 #bgcolor = "#%02X%02X%02X" % (bgc.red(), bgc.green(), bgc.blue())
22
23 self.fig = Figure(figsize=(width, height), dpi=dpi, facecolor=bgcolor, edgecolor=bgcolor)
24 self.axes = self.fig.add_subplot(111)
25 # We want the axes cleared every time plot() is called
26 self.axes.hold(False)
27
28 self.compute_initial_figure()
29
30 FigureCanvas.__init__(self, self.fig)
31 self.reparent(parent, QPoint(0, 0))
32
33 FigureCanvas.setSizePolicy(self,
34 QSizePolicy.Expanding,
35 QSizePolicy.Expanding)
36 FigureCanvas.updateGeometry(self)
37
38 def sizeHint(self):
39 w = self.fig.get_figwidth()
40 h = self.fig.get_figheight()
41 return QSize(w, h)
42
43 def minimumSizeHint(self):
44 return QSize(10, 10)
45
46 def compute_initial_figure(self):
47 t = arange(0.0, 3.0, 0.01)
48 s = sin(2*pi*t)
49 self.axes.plot(t, s)
New Attachment
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2006-01-22 20:42:18, 77.0 KB) [[attachment:designer_edit_custom_widgets.png]]
- [get | view] (2006-01-22 20:42:46, 26.2 KB) [[attachment:designer_form_settings_comment.png]]
- [get | view] (2006-01-22 20:42:35, 96.7 KB) [[attachment:designer_full_workspace.png]]
- [get | view] (2006-01-22 20:42:25, 39.9 KB) [[attachment:designer_new_widget.png]]
- [get | view] (2006-01-22 20:41:58, 26.0 KB) [[attachment:designer_newopen.png]]
- [get | view] (2006-01-22 20:42:08, 52.5 KB) [[attachment:designer_wizard.png]]
- [get | view] (2006-01-22 20:45:29, 15.8 KB) [[attachment:ipython_interacted.png]]
- [get | view] (2006-01-22 20:45:20, 20.4 KB) [[attachment:ipython_invoked.png]]
- [get | view] (2006-01-22 20:44:16, 0.1 KB) [[attachment:main_mpl_tutorial.py]]
- [get | view] (2006-01-22 20:43:39, 1.5 KB) [[attachment:mplwidget.py]]
- [get | view] (2006-01-22 20:43:47, 1.1 KB) [[attachment:mplwidget_tutorial.py]]
- [get | view] (2006-01-22 20:43:59, 3.7 KB) [[attachment:mplwidget_tutorial.ui]]