1010
1111import sys
1212from PyQt4 .Qt import *
13- #from PyQt4.Qwt5 import *
1413from qwt import *
15- import PyQt4 . Qwt5 . anynumpy as np
14+ import numpy as np
1615
1716
1817print_xpm = ['32 32 12 1' ,
@@ -194,30 +193,22 @@ def __init__(self, *args):
194193
195194 self .setDamp (0.01 )
196195
197- # __init__()
198-
199196 def showData (self , frequency , amplitude , phase ):
200197 self .curve1 .setData (frequency , amplitude )
201198 self .curve2 .setData (frequency , phase )
202199
203- # showData()
204-
205200 def showPeak (self , frequency , amplitude ):
206201 self .peakMarker .setValue (frequency , amplitude )
207202 label = self .peakMarker .label ()
208203 label .setText ('Peak: %4g dB' % amplitude )
209204 self .peakMarker .setLabel (label )
210205
211- # showPeak()
212-
213206 def show3dB (self , frequency ):
214207 self .dB3Marker .setValue (frequency , 0.0 )
215208 label = self .dB3Marker .label ()
216209 label .setText ('-3dB at f = %4g' % frequency )
217210 self .dB3Marker .setLabel (label )
218211
219- # show3dB()
220-
221212 def setDamp (self , d ):
222213 self .damping = d
223214 # Numerical Python: f, g, a and p are NumPy arrays!
@@ -237,10 +228,6 @@ def setDamp(self, d):
237228
238229 self .replot ()
239230
240- # setDamp()
241-
242- # class BodePlot
243-
244231
245232class BodeDemo (QMainWindow ):
246233
@@ -252,35 +239,6 @@ def __init__(self, *args):
252239
253240 self .setContextMenuPolicy (Qt .NoContextMenu )
254241
255- # self.zoomers = []
256- # zoomer = QwtPlotZoomer(
257- # QwtPlot.xBottom,
258- # QwtPlot.yLeft,
259- # QwtPicker.DragSelection,
260- # QwtPicker.AlwaysOff,
261- # self.plot.canvas())
262- # zoomer.setRubberBandPen(QPen(Qt.green))
263- # self.zoomers.append(zoomer)
264- #
265- # zoomer = QwtPlotZoomer(
266- # QwtPlot.xTop,
267- # QwtPlot.yRight,
268- # QwtPicker.PointSelection | QwtPicker.DragSelection,
269- # QwtPicker.AlwaysOff,
270- # self.plot.canvas())
271- # zoomer.setRubberBand(QwtPicker.NoRubberBand)
272- # self.zoomers.append(zoomer)
273-
274- # self.picker = QwtPlotPicker(
275- # QwtPlot.xBottom,
276- # QwtPlot.yLeft,
277- # QwtPicker.PointSelection | QwtPicker.DragSelection,
278- # QwtPlotPicker.CrossRubberBand,
279- # QwtPicker.AlwaysOn,
280- # self.plot.canvas())
281- # self.picker.setRubberBandPen(QPen(Qt.green))
282- # self.picker.setTrackerPen(QPen(Qt.cyan))
283-
284242 self .setCentralWidget (self .plot )
285243
286244 toolBar = QToolBar (self )
@@ -316,32 +274,11 @@ def __init__(self, *args):
316274 dampLayout .addWidget (QLabel ("Damping Factor" , dampBox ), 0 )
317275 dampLayout .addSpacing (10 )
318276
319- # self.cntDamp = QwtCounter(dampBox)
320- # self.cntDamp.setRange(0.01, 5.0, 0.01)
321- # self.cntDamp.setValue(0.01)
322- # dampLayout.addWidget(self.cntDamp, 10)
323-
324277 toolBar .addWidget (dampBox )
325278
326279 self .statusBar ()
327280
328- self .zoom (False )
329281 self .showInfo ()
330-
331- # self.connect(self.cntDamp,
332- # SIGNAL('valueChanged(double)'),
333- # self.plot.setDamp)
334- self .connect (btnZoom ,
335- SIGNAL ('toggled(bool)' ),
336- self .zoom )
337- # self.connect(self.picker,
338- # SIGNAL('moved(const QPoint &)'),
339- # self.moved)
340- # self.connect(self.picker,
341- # SIGNAL('selected(const QPolygon &)'),
342- # self.selected)
343-
344- # __init__()
345282
346283 def print_ (self ):
347284 printer = QPrinter (QPrinter .HighResolution )
@@ -366,48 +303,22 @@ def print_(self):
366303 renderer .renderTo (self .plot , printer )
367304
368305 def exportDocument (self ):
369- self .plot .exportTo ("bode.pdf" )
370-
371- def zoom (self , on ):
372- # self.zoomers[0].setEnabled(on)
373- # self.zoomers[0].zoom(0)
374- #
375- # self.zoomers[1].setEnabled(on)
376- # self.zoomers[1].zoom(0)
377-
378- # if on:
379- # self.picker.setRubberBand(Qwt.QwtPicker.NoRubberBand)
380- # else:
381- # self.picker.setRubberBand(Qwt.QwtPicker.CrossRubberBand)
382-
383- self .showInfo ()
384-
385- # zoom()
306+ renderer = QwtPlotRenderer (self .plot )
307+ renderer .exportTo (self .plot , "bode" )
386308
387309 def showInfo (self , text = "" ):
388- # if not text:
389- # if self.picker.rubberBand():
390- # text = 'Cursor Pos: Press left mouse button in plot region'
391- # else:
392- # text = 'Zoom: Press mouse button and drag'
393-
394310 self .statusBar ().showMessage (text )
395311
396- # showInfo()
397-
398312 def moved (self , point ):
399313 info = "Freq=%g, Ampl=%g, Phase=%g" % (
400314 self .plot .invTransform (Qwt .QwtPlot .xBottom , point .x ()),
401315 self .plot .invTransform (Qwt .QwtPlot .yLeft , point .y ()),
402316 self .plot .invTransform (Qwt .QwtPlot .yRight , point .y ()))
403317 self .showInfo (info )
404318
405- # moved()
406-
407319 def selected (self , _ ):
408320 self .showInfo ()
409321
410- # selected()
411322
412323def make ():
413324 demo = BodeDemo ()
0 commit comments