def __init__(self, *args): qt.QFrame.__init__(self, *args) self.frequencySlider = Qwt.QwtSlider(self, qt.Qt.Horizontal, Qwt.QwtSlider.TopScale) self.frequencySlider.setScaleMaxMinor(5) self.frequencySlider.setScaleMaxMajor(12) self.frequencySlider.setThumbLength(80) self.frequencySlider.setBorderWidth(1) self.frequencySlider.setRange(87.5, 108, 0.01, 10) self.tuningThermo = TuningThermo(self) self.frequencyWheel = Qwt.QwtWheel(self) self.frequencyWheel.setMass(0.5) self.frequencyWheel.setRange(87.5, 108, 0.01) self.frequencyWheel.setTotalAngle(3600.0) self.connect(self.frequencyWheel, qt.SIGNAL("valueChanged(double)"), self.adjustFreq) self.connect(self.frequencySlider, qt.SIGNAL("valueChanged(double)"), self.adjustFreq) mainLayout = qt.QVBoxLayout(self) mainLayout.setMargin(10) mainLayout.setSpacing(5) mainLayout.addWidget(self.frequencySlider) hLayout = qt.QHBoxLayout() hLayout.setMargin(0) hLayout.addWidget(self.tuningThermo, 0) hLayout.addStretch(5) hLayout.addWidget(self.frequencyWheel, 2) mainLayout.addLayout(hLayout)
def __init__(self, parent=None): qt.QMainWindow.__init__(self, parent) # Initialize a QwPlot central widget self.plot = Qwt.QwtPlot(self) self.plot.setTitle('left-click & drag to zoom') self.plot.setCanvasBackground(qt.Qt.white) self.plot.plotLayout().setCanvasMargin(0) self.plot.plotLayout().setAlignCanvasToScales(True) self.setCentralWidget(self.plot) grid = Qwt.QwtPlotGrid() pen = qt.QPen(qt.Qt.DotLine) pen.setColor(qt.Qt.black) pen.setWidth(0) grid.setPen(pen) grid.attach(self.plot) self.__initTracking() self.__initZooming() self.__initToolBar() # Finalize self.counter.setValue(10) self.go(self.counter.value())
def make(): # create a plot with a white canvas demo = Qwt.QwtPlot(Qwt.QwtText("Errorbar Demonstation")) demo.setCanvasBackground(qt.Qt.white) demo.plotLayout().setAlignCanvasToScales(True) grid = Qwt.QwtPlotGrid() grid.attach(demo) grid.setPen(qt.QPen(qt.Qt.black, 0, qt.Qt.DotLine)) # calculate data and errors for a curve with error bars x = arange(0, 10.1, 0.5, Float) y = sin(x) dy = 0.2 * abs(y) # dy = (0.15 * abs(y), 0.25 * abs(y)) # uncomment for asymmetric error bars dx = 0.2 # all error bars the same size errorOnTop = False # uncomment to draw the curve on top of the error bars # errorOnTop = True # uncomment to draw the error bars on top of the curve curve = ErrorBarPlotCurve( x=x, y=y, dx=dx, dy=dy, curvePen=qt.QPen(qt.Qt.black, 2), curveSymbol=Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, qt.QBrush(qt.Qt.red), qt.QPen(qt.Qt.black, 2), qt.QSize(9, 9)), errorPen=qt.QPen(qt.Qt.blue, 2), errorCap=10, errorOnTop=errorOnTop, ) curve.attach(demo) demo.resize(400, 300) demo.show() return demo
def __init__(self, *args): qt.QWidget.__init__(self, *args) layout = qt.QGridLayout(self) # try to create a plot for SciPy arrays try: # import does_not_exist import numpy # make a curve and copy the data numpy_curve = Qwt.QwtPlotCurve('y = lorentzian(x)') x = numpy.arange(0.0, 10.0, 0.01) y = lorentzian(x) numpy_curve.setData(x, y) # here, we know we can plot NumPy arrays numpy_plot = Qwt.QwtPlot(self) numpy_plot.setTitle('numpy array') numpy_plot.setCanvasBackground(qt.Qt.white) numpy_plot.plotLayout().setCanvasMargin(0) numpy_plot.plotLayout().setAlignCanvasToScales(True) # insert a curve and make it red numpy_curve.attach(numpy_plot) numpy_curve.setPen(qt.QPen(qt.Qt.red)) layout.addWidget(numpy_plot, 0, 0) numpy_plot.replot() except ImportError, message: print "%s: %s" % (ImportError, message) print "Install NumPy to plot NumPy arrays"
def __init__(self, title=Qwt.QwtText()): Qwt.QwtPlotItem.__init__(self) if not isinstance(title, Qwt.QwtText): self.title = Qwt.QwtText(str(title)) else: self.title = title self.setItemAttribute(Qwt.QwtPlotItem.Legend) self.xyzs = None
def __init__(self, *args): qt.QMainWindow.__init__(self, *args) self.plot = Qwt.QwtPlot(self) self.plot.setTitle("A Simple Map Demonstration") self.plot.setCanvasBackground(qt.Qt.white) self.plot.setAxisTitle(Qwt.QwtPlot.xBottom, "x") self.plot.setAxisTitle(Qwt.QwtPlot.yLeft, "y") self.plot.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 1.0) self.plot.setAxisScale(Qwt.QwtPlot.yLeft, 0.0, 1.0) self.setCentralWidget(self.plot) # Initialize map data self.count = self.i = 1000 self.xs = zeros(self.count, Float) self.ys = zeros(self.count, Float) self.kappa = 0.2 self.curve = Qwt.QwtPlotCurve("Map") self.curve.attach(self.plot) self.curve.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, qt.QBrush(qt.Qt.red), qt.QPen(qt.Qt.blue), qt.QSize(5, 5))) self.curve.setPen(qt.QPen(qt.Qt.cyan)) toolBar = qt.QToolBar(self) qt.QLabel("Count:", toolBar) sizeCounter = Qwt.QwtCounter(toolBar) toolBar.addSeparator() sizeCounter.setRange(0, 1000000, 100) sizeCounter.setValue(self.count) sizeCounter.setNumButtons(3) self.connect( sizeCounter, qt.SIGNAL('valueChanged(double)'), self.setCount) qt.QLabel("Ticks (ms):", toolBar) tickCounter = Qwt.QwtCounter(toolBar) toolBar.addSeparator() # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz) self.ticks = 10 tickCounter.setRange(0, 1000, 1) tickCounter.setValue(self.ticks) tickCounter.setNumButtons(3) self.connect( tickCounter, qt.SIGNAL('valueChanged(double)'), self.setTicks) self.tid = self.startTimer(self.ticks) self.timer_tic = None self.user_tic = None self.system_tic = None self.plot.replot()
def main(args): app = qt.QApplication(args) demo = make() app.setMainWidget(demo) zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, demo.canvas()) zoomer.setRubberBandPen(qt.QPen(qt.Qt.green)) picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.NoSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, demo.canvas()) picker.setTrackerPen(qt.QPen(qt.Qt.red)) sys.exit(app.exec_loop())
def setData(self, xyzs, xRange=None, yRange=None): self.xyzs = xyzs shape = xyzs.shape if not xRange: xRange = (0, shape[0]) if not yRange: yRange = (0, shape[1]) self.xMap = Qwt.QwtScaleMap(0, xyzs.shape[0], *xRange) self.plot().setAxisScale(Qwt.QwtPlot.xBottom, *xRange) self.yMap = Qwt.QwtScaleMap(0, xyzs.shape[1], *yRange) self.plot().setAxisScale(Qwt.QwtPlot.yLeft, *yRange) self.image = Qwt.toQImage(bytescale(self.xyzs)).mirror(False, True) for i in range(0, 256): self.image.setColor(i, qt.qRgb(i, 0, 255 - i))
def __init__(self, *args): QtBlissGraph.__init__(self, *args) f = self.parent().font() t = qwt.QwtText('') t.setFont(f) self.setAxisTitle(qwt.QwtPlot.xBottom, t) self.setAxisTitle(qwt.QwtPlot.yLeft, t)
def createSlider(self, parent, sliderType): if sliderType == 0: slider = Qwt.QwtSlider(parent, qt.Qt.Horizontal, Qwt.QwtSlider.TopScale, Qwt.QwtSlider.BgTrough) slider.setThumbWidth(10) slider.setRange(-10.0, 10.0, 1.0, 0) # paging disabled return slider if sliderType == 1: slider = Qwt.QwtSlider(parent, qt.Qt.Horizontal, Qwt.QwtSlider.NoScale, Qwt.QwtSlider.BgBoth) slider.setRange(0.0, 1.0, 0.01, 5) return slider if sliderType == 2: slider = Qwt.QwtSlider(parent, qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) slider.setThumbWidth(25) slider.setThumbLength(12) slider.setRange(1000.0, 3000.0, 10.0, 10) return slider if sliderType == 3: slider = Qwt.QwtSlider(parent, qt.Qt.Vertical, Qwt.QwtSlider.LeftScale, Qwt.QwtSlider.BgSlot) slider.setRange(0.0, 100.0, 1.0, 5) slider.setScaleMaxMinor(5) return slider if sliderType == 4: slider = Qwt.QwtSlider(parent, qt.Qt.Vertical, Qwt.QwtSlider.NoScale, Qwt.QwtSlider.BgTrough) slider.setRange(0.0,100.0,1.0, 10) return slider if sliderType == 5: slider = Qwt.QwtSlider(parent, qt.Qt.Vertical, Qwt.QwtSlider.RightScale, Qwt.QwtSlider.BgBoth) slider.setScaleEngine(Qwt.QwtLog10ScaleEngine()) slider.setThumbWidth(20) slider.setBorderWidth(1) slider.setRange(0.0, 4.0, 0.01) slider.setScale(1.0, 1.0e4) slider.setScaleMaxMinor(10) return slider return None
def __init__(self, *args): QtBlissGraph.__init__(self, *args) picker = qwt.QwtPlotPicker(qwt.QwtPlot.xBottom, qwt.QwtPlot.yLeft, qwt.QwtPicker.PointSelection, qwt.QwtPlotPicker.CrossRubberBand, qwt.QwtPicker.AlwaysOn, self.canvas()) picker.connect(picker, SIGNAL('selected(const QwtDoublePoint&)'), self.pickPoint)
def __initZooming(self): """Initialize zooming """ self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.plot.canvas()) self.zoomer.setRubberBandPen(qt.QPen(qt.Qt.black))
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) # make a QwtPlot widget self.setTitle('SimpleDemo.py') self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend) # a variation on the C++ example self.plotLayout().setAlignCanvasToScales(True) grid = Qwt.QwtPlotGrid() grid.attach(self) grid.setPen(qt.QPen(qt.Qt.black, 0, qt.Qt.DotLine)) # set axis titles self.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->') self.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->') # insert a few curves cSin = Qwt.QwtPlotCurve('y = sin(x)') cSin.setPen(qt.QPen(qt.Qt.red)) cSin.attach(self) cCos = Qwt.QwtPlotCurve('y = cos(x)') cCos.setPen(qt.QPen(qt.Qt.blue)) cCos.attach(self) # initialize the data cSin.setData(SimpleData(math.sin, 100)) cCos.setData(SimpleData(math.cos, 100)) # insert a horizontal marker at y = 0 mY = Qwt.QwtPlotMarker() mY.setLabel(Qwt.QwtText('y = 0')) mY.setLabelAlignment(qt.Qt.AlignRight | qt.Qt.AlignTop) mY.setLineStyle(Qwt.QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) # insert a vertical marker at x = 2 pi mX = Qwt.QwtPlotMarker() mX.setLabel(Qwt.QwtText('x = 2 pi')) mX.setLabelAlignment(qt.Qt.AlignRight | qt.Qt.AlignTop) mX.setLineStyle(Qwt.QwtPlotMarker.VLine) mX.setXValue(2 * math.pi) mX.attach(self) # replot self.replot()
def __init__(self, title, min, max, parent): qt.QWidget.__init__(self, parent) self.knob = Qwt.QwtKnob(self) self.knob.setRange(min, max, 0, 1) self.knob.setScaleMaxMajor(10) self.knob.setKnobWidth(50) self.label = qt.QLabel(title, self) self.label.setAlignment(qt.Qt.AlignTop | qt.Qt.AlignHCenter) self.setSizePolicy(qt.QSizePolicy.MinimumExpanding, qt.QSizePolicy.MinimumExpanding)
def __init__( self, x=[], y=[], dx=None, dy=None, curvePen=qt.QPen(qt.Qt.NoPen), curveStyle=Qwt.QwtPlotCurve.Lines, curveSymbol=Qwt.QwtSymbol(), errorPen=qt.QPen(qt.Qt.NoPen), errorCap=0, errorOnTop=False, ): """A curve of x versus y data with error bars in dx and dy. Horizontal error bars are plotted if dx is not None. Vertical error bars are plotted if dy is not None. x and y must be sequences with a shape (N,) and dx and dy must be sequences (if not None) with a shape (), (N,), or (2, N): - if dx or dy has a shape () or (N,), the error bars are given by (x-dx, x+dx) or (y-dy, y+dy), - if dx or dy has a shape (2, N), the error bars are given by (x-dx[0], x+dx[1]) or (y-dy[0], y+dy[1]). curvePen is the pen used to plot the curve curveStyle is the style used to plot the curve curveSymbol is the symbol used to plot the symbols errorPen is the pen used to plot the error bars errorCap is the size of the error bar caps errorOnTop is a boolean: - if True, plot the error bars on top of the curve, - if False, plot the curve on top of the error bars. """ Qwt.QwtPlotCurve.__init__(self) self.setData(x, y, dx, dy) self.setPen(curvePen) self.setStyle(curveStyle) self.setSymbol(curveSymbol) self.errorPen = errorPen self.errorCap = errorCap self.errorOnTop = errorOnTop
def setData(self, xyzs, xRange = None, yRange = None): self.xyzs = xyzs shape = xyzs.shape if not xRange: xRange = (0, shape[0]) if not yRange: yRange = (0, shape[1]) self.xMap = Qwt.QwtScaleMap(0, xyzs.shape[0], *xRange) self.plot().setAxisScale(Qwt.QwtPlot.xBottom, *xRange) self.yMap = Qwt.QwtScaleMap(0, xyzs.shape[1], *yRange) self.plot().setAxisScale(Qwt.QwtPlot.yLeft, *yRange) self.image = Qwt.toQImage(bytescale(self.xyzs)).mirror(False, True) for i in range(0, 256): self.image.setColor(i, qt.qRgb(i, 0, 255-i))
def __init__(self, *args): qt.QWidget.__init__(self, *args) self.thermo = Qwt.QwtThermo(self) self.thermo.setOrientation(qt.Qt.Horizontal, Qwt.QwtThermo.NoScale) self.thermo.setRange(0.0, 1.0) self.thermo.setFillColor(qt.Qt.green) label = qt.QLabel("Tuning", self) label.setAlignment(qt.Qt.AlignCenter) layout = qt.QVBoxLayout(self) layout.setMargin(0) layout.addWidget(self.thermo) layout.addWidget(label) self.setFixedWidth(3 * label.sizeHint().width())
def __init__(self, title, parent): qt.QWidget.__init__(self, parent) self.thermo = Qwt.QwtThermo(self) self.thermo.setPipeWidth(6) self.thermo.setRange(-40, 10) self.thermo.setFillColor(qt.Qt.green) self.thermo.setAlarmColor(qt.Qt.red) self.thermo.setAlarmLevel(0.0) self.thermo.setAlarmEnabled(True) label = qt.QLabel(title, self) label.setAlignment(qt.Qt.AlignTop | qt.Qt.AlignLeft) layout = qt.QVBoxLayout(self) layout.setMargin(0) layout.setSpacing(0) layout.addWidget(self.thermo, 10) layout.addWidget(label)
def __init__(self, parent=None, orientation=qt.Qt.Horizontal): qt.QWidget.__init__(self, parent) if orientation == qt.Qt.Horizontal: alignment = qt.Qt.AlignHCenter | qt.Qt.AlignTop layout = qt.QHBoxLayout(self) else: alignment = qt.Qt.AlignVCenter | qt.Qt.AlignLeft layout = qt.QVBoxLayout(self) layout.setMargin(0) layout.setSpacing(0) self.slider = Qwt5.QwtSlider(self, orientation) self.label = qt.QLabel("0", self) self.label.setAlignment(alignment) self.label.setFixedWidth(self.label.fontMetrics().width('100.99')) layout.addWidget(self.slider) layout.addWidget(self.label) self.connect(self.slider, qt.SIGNAL('valueChanged(double)'), self.setNum)
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) # make a QwtPlot widget self.setTitle('ReallySimpleDemo.py') self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend) # set axis titles self.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->') self.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->') # insert a few curves cSin = Qwt.QwtPlotCurve('y = sin(x)') cSin.setPen(qt.QPen(qt.Qt.red)) cSin.attach(self) cCos = Qwt.QwtPlotCurve('y = cos(x)') cCos.setPen(qt.QPen(qt.Qt.blue)) cCos.attach(self) # make a Numeric array for the horizontal data x = arange(0.0, 10.0, 0.1) # initialize the data cSin.setData(x, sin(x)) cCos.setData(x, cos(x)) # insert a horizontal marker at y = 0 mY = Qwt.QwtPlotMarker() mY.setLabel(Qwt.QwtText('y = 0')) mY.setLabelAlignment(qt.Qt.AlignRight | qt.Qt.AlignTop) mY.setLineStyle(Qwt.QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) # insert a vertical marker at x = 2 pi mX = Qwt.QwtPlotMarker() mX.setLabel(Qwt.QwtText('x = 2 pi')) mX.setLabelAlignment(qt.Qt.AlignRight | qt.Qt.AlignTop) mX.setLineStyle(Qwt.QwtPlotMarker.VLine) mX.setXValue(2 * pi) mX.attach(self) # replot self.replot()
def boundingRect(self): """Return the bounding rectangle of the data, error bars included. """ if self.__dx is None: xmin = min(self.__x) xmax = max(self.__x) elif len(self.__dx.shape) in [0, 1]: xmin = min(self.__x - self.__dx) xmax = max(self.__x + self.__dx) else: xmin = min(self.__x - self.__dx[0]) xmax = max(self.__x + self.__dx[1]) if self.__dy is None: ymin = min(self.__y) ymax = max(self.__y) elif len(self.__dy.shape) in [0, 1]: ymin = min(self.__y - self.__dy) ymax = max(self.__y + self.__dy) else: ymin = min(self.__y - self.__dy[0]) ymax = max(self.__y + self.__dy[1]) return Qwt.QwtDoubleRect(xmin, ymin, xmax - xmin, ymax - ymin)
def __init__(self, *args): Qt.QMainWindow.__init__(self, *args) self.plot = BodePlot(self) self.plot.setMargin(5) self.zoomers = [] zoomer = Qwt.QwtPlotZoomer( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.plot.canvas()) zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.zoomers.append(zoomer) zoomer = Qwt.QwtPlotZoomer( Qwt.QwtPlot.xTop, Qwt.QwtPlot.yRight, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.plot.canvas()) zoomer.setRubberBand(Qwt.QwtPicker.NoRubberBand) self.zoomers.append(zoomer) self.picker = Qwt.QwtPlotPicker( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.plot.canvas()) self.picker.setRubberBandPen(Qt.QPen(Qt.Qt.green)) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan)) self.setCentralWidget(self.plot) toolBar = Qt.QToolBar(self) btnZoom = Qt.QToolButton(toolBar) btnZoom.setTextLabel("Zoom") btnZoom.setPixmap(Qt.QPixmap(zoom_xpm)) btnZoom.setToggleButton(True) btnZoom.setUsesTextLabel(True) btnPrint = Qt.QToolButton(toolBar) btnPrint.setTextLabel("Print") btnPrint.setPixmap(Qt.QPixmap(print_xpm)) btnPrint.setUsesTextLabel(True) toolBar.addSeparator() dampBox = Qt.QWidget(toolBar) dampLayout = Qt.QHBoxLayout(dampBox) dampLayout.setSpacing(0) dampLayout.addWidget(Qt.QWidget(dampBox), 10) # spacer dampLayout.addWidget(Qt.QLabel("Damping Factor", dampBox), 0) dampLayout.addSpacing(10) self.cntDamp = Qwt.QwtCounter(dampBox) self.cntDamp.setRange(0.01, 5.0, 0.01) self.cntDamp.setValue(0.01) dampLayout.addWidget(self.cntDamp, 10) toolBar.setStretchableWidget(dampBox) self.statusBar() self.zoom(False) self.showInfo() self.connect( self.cntDamp, Qt.SIGNAL('valueChanged(double)'), self.plot.setDamp) self.connect( btnPrint, Qt.SIGNAL('clicked()'), self.print_) self.connect( btnZoom, Qt.SIGNAL('toggled(bool)'), self.zoom) self.connect( self.picker, Qt.SIGNAL('moved(const QPoint &)'), self.moved) self.connect( self.picker, Qt.SIGNAL('selected(const QwtPolygon &)'), self.selected)
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) self.setTitle('Frequency Response of a 2<sup>nd</sup>-order System') self.setCanvasBackground(Qt.Qt.darkBlue) # legend legend = Qwt.QwtLegend() legend.setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Sunken) legend.setItemMode(Qwt.QwtLegend.ClickableItem) self.insertLegend(legend, Qwt.QwtPlot.BottomLegend) # grid self.grid = Qwt.QwtPlotGrid() self.grid.enableXMin(True) self.grid.setMajPen(Qt.QPen(Qt.Qt.white, 0, Qt.Qt.DotLine)) self.grid.setMinPen(Qt.QPen(Qt.Qt.gray, 0 , Qt.Qt.DotLine)) self.grid.attach(self) # axes self.enableAxis(Qwt.QwtPlot.yRight) self.setAxisTitle(Qwt.QwtPlot.xBottom, u'\u03c9/\u03c9<sub>0</sub>') self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Amplitude [dB]') self.setAxisTitle(Qwt.QwtPlot.yRight, u'Phase [\u00b0]') self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 6) self.setAxisMaxMinor(Qwt.QwtPlot.xBottom, 10) self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) # curves self.curve1 = Qwt.QwtPlotCurve('Amplitude') self.curve1.setPen(Qt.QPen(Qt.Qt.yellow)) self.curve1.setYAxis(Qwt.QwtPlot.yLeft) self.curve1.attach(self) self.curve2 = Qwt.QwtPlotCurve('Phase') self.curve2.setPen(Qt.QPen(Qt.Qt.cyan)) self.curve2.setYAxis(Qwt.QwtPlot.yRight) self.curve2.attach(self) # alias fn = self.fontInfo().family() # marker self.dB3Marker = m = Qwt.QwtPlotMarker() m.setValue(0.0, 0.0) m.setLineStyle(Qwt.QwtPlotMarker.VLine) m.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignBottom) m.setLinePen(Qt.QPen(Qt.Qt.green, 2, Qt.Qt.DashDotLine)) text = Qwt.QwtText('') text.setColor(Qt.Qt.green) text.setBackgroundBrush(Qt.QBrush(Qt.Qt.red)) text.setFont(Qt.QFont(fn, 12, Qt.QFont.Bold)) m.setLabel(text) m.attach(self) self.peakMarker = m = Qwt.QwtPlotMarker() m.setLineStyle(Qwt.QwtPlotMarker.HLine) m.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignBottom) m.setLinePen(Qt.QPen(Qt.Qt.red, 2, Qt.Qt.DashDotLine)) text = Qwt.QwtText('') text.setColor(Qt.Qt.red) text.setBackgroundBrush(Qt.QBrush(self.canvasBackground())) text.setFont(Qt.QFont(fn, 12, Qt.QFont.Bold)) m.setLabel(text) m.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Diamond, Qt.QBrush(Qt.Qt.yellow), Qt.QPen(Qt.Qt.green), Qt.QSize(7,7))) m.attach(self) # text marker m = Qwt.QwtPlotMarker() m.setValue(0.1, -20.0) m.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignBottom) text = Qwt.QwtText( u'[1-(\u03c9/\u03c9<sub>0</sub>)<sup>2</sup>+2j\u03c9/Q]' '<sup>-1</sup>' ) text.setFont(Qt.QFont(fn, 12, Qt.QFont.Bold)) text.setColor(Qt.Qt.blue) text.setBackgroundBrush(Qt.QBrush(Qt.Qt.yellow)) text.setBackgroundPen(Qt.QPen(Qt.Qt.red, 2)) m.setLabel(text) m.attach(self) self.setDamp(0.01)
def __initToolBar(self): """Initialize the toolbar """ toolBar = qt.QToolBar(self) qt.QLabel('Bars', toolBar) self.counter = Qwt.QwtCounter(toolBar) self.counter.setRange(0, 10000, 1) self.counter.setNumButtons(3) toolBar.addSeparator() qt.QLabel('Mouse', toolBar) mouseComboBox = qt.QComboBox(toolBar) for name in ('3 buttons (PyQwt)', '1 button', '2 buttons', '3 buttons (Qwt)'): mouseComboBox.insertItem(name) mouseComboBox.setCurrentItem(0) toolBar.addSeparator() self.setZoomerMousePattern(0) qt.QWhatsThis.whatsThisButton(toolBar) qt.QWhatsThis.add( self.plot.canvas(), 'A QwtPlotZoomer lets you zoom infinitely deep ' 'by saving the zoom states on a stack.\n\n' 'You can:\n' '- select a zoom region\n' '- unzoom all\n' '- walk down the stack\n' '- walk up the stack.\n\n' 'The combo box in the toolbar lets you attach ' 'different sets of mouse events to those actions.' ) qt.QWhatsThis.add( self.counter, 'Select the number of bars' ) qt.QWhatsThis.add( mouseComboBox, 'Configure the zoomer mouse buttons.\n\n' '3 buttons (PyQwt style):\n' '- left-click & drag to zoom\n' '- middle-click to unzoom all\n' '- right-click to walk down the stack\n' '- shift-right-click to walk up the stack.\n' '1 button:\n' '- click & drag to zoom\n' '- control-click to unzoom all\n' '- alt-click to walk down the stack\n' '- shift-alt-click to walk up the stack.\n' '2 buttons:\n' '- left-click & drag to zoom\n' '- right-click to unzoom all\n' '- alt-left-click to walk down the stack\n' '- alt-shift-left-click to walk up the stack.\n' '3 buttons (Qwt style):\n' '- left-click & drag to zoom\n' '- right-click to unzoom all\n' '- middle-click to walk down the stack\n' '- shift-middle-click to walk up the stack.\n\n' 'If some of those key combinations interfere with ' 'your Window manager, press the:\n' '- escape-key to unzoom all\n' '- minus-key to walk down the stack\n' '- plus-key to walk up the stack.' ) self.connect(self.counter, qt.SIGNAL('valueChanged(double)'), self.go) self.connect(mouseComboBox, qt.SIGNAL('activated(int)'), self.setZoomerMousePattern)
def __init__(self, *args): Qt.QFrame.__init__(self, *args) self.xMap = Qwt.QwtScaleMap() self.xMap.setScaleInterval(-0.5, 10.5) self.yMap = Qwt.QwtScaleMap() self.yMap.setScaleInterval(-1.1, 1.1) # frame style self.setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Raised) self.setLineWidth(2) self.setMidLineWidth(3) # calculate values self.x = arange(0, 10.0, 10.0 / 27) self.y = sin(self.x) * cos(2 * self.x) # make curves with different styles self.curves = [] self.titles = [] # curve 0 self.titles.append('Style: Lines/Fitted, Symbol: Cross') curve = Qwt.QwtPlotCurve() curve.setPen(Qt.QPen(Qt.Qt.darkGreen)) curve.setStyle(Qwt.QwtPlotCurve.Lines) curve.setCurveAttribute(Qwt.QwtPlotCurve.Fitted) curve.setSymbol( Qwt.QwtSymbol(Qwt.QwtSymbol.Cross, Qt.QBrush(), Qt.QPen(Qt.Qt.black), Qt.QSize(5, 5))) self.curves.append(curve) # curve 1 self.titles.append('Style: Sticks, Symbol: Ellipse') curve = Qwt.QwtPlotCurve() curve.setPen(Qt.QPen(Qt.Qt.red)) curve.setStyle(Qwt.QwtPlotCurve.Sticks) curve.setSymbol( Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, Qt.QBrush(Qt.Qt.yellow), Qt.QPen(Qt.Qt.blue), Qt.QSize(5, 5))) self.curves.append(curve) # curve 2 self.titles.append('Style: Lines, Symbol: None') curve = Qwt.QwtPlotCurve() curve.setPen(Qt.QPen(Qt.Qt.darkBlue)) curve.setStyle(Qwt.QwtPlotCurve.Lines) self.curves.append(curve) # curve 3 self.titles.append('Style: Steps, Symbol: None') curve = Qwt.QwtPlotCurve() curve.setPen(Qt.QPen(Qt.Qt.darkCyan)) curve.setStyle(Qwt.QwtPlotCurve.Steps) self.curves.append(curve) # curve 4 self.titles.append('Style: NoCurve, Symbol: XCross') curve = Qwt.QwtPlotCurve() curve.setStyle(Qwt.QwtPlotCurve.NoCurve) curve.setSymbol( Qwt.QwtSymbol(Qwt.QwtSymbol.XCross, Qt.QBrush(), Qt.QPen(Qt.Qt.darkMagenta), Qt.QSize(5, 5))) self.curves.append(curve) # attach data, using Numeric for curve in self.curves: curve.setData(self.x, self.y)
numpy_curve.setPen(qt.QPen(qt.Qt.red)) layout.addWidget(numpy_plot, 0, 0) numpy_plot.replot() except ImportError, message: print "%s: %s" % (ImportError, message) print "Install NumPy to plot NumPy arrays" except TypeError, message: print "%s: %s" % (TypeError, message) print "Rebuild PyQwt to plot NumPy arrays" # try to create a plot for Numeric arrays try: # import does_not_exist import Numeric # make a curve and copy the data numeric_curve = Qwt.QwtPlotCurve('y = lorentzian(x)') x = Numeric.arange(0.0, 10.0, 0.01) y = lorentzian(x) numeric_curve.setData(x, y) # here, we know we can plot Numeric arrays numeric_plot = Qwt.QwtPlot(self) numeric_plot.setTitle('Numeric array') numeric_plot.setCanvasBackground(qt.Qt.white) numeric_plot.plotLayout().setCanvasMargin(0) numeric_plot.plotLayout().setAlignCanvasToScales(True) # insert a curve and it red numeric_curve.attach(numeric_plot) numeric_curve.setPen(qt.QPen(qt.Qt.red)) layout.addWidget(numeric_plot, 0, 1) numeric_plot.replot() except ImportError, message:
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) # set plot title self.setTitle('ImagePlot: (un)zoom & (un)hide') # set plot layout self.plotLayout().setMargin(0) self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(True) # set legend legend = Qwt.QwtLegend() legend.setItemMode(Qwt.QwtLegend.ClickableItem) self.insertLegend(legend, Qwt.QwtPlot.RightLegend) # set axis titles self.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (s)') self.setAxisTitle(Qwt.QwtPlot.yLeft, 'frequency (Hz)') # calculate 3 NumPy arrays x = arange(-2 * pi, 2 * pi, 0.01) y = pi * sin(x) z = 4 * pi * cos(x) * cos(x) * sin(x) # attach a curve curve = Qwt.QwtPlotCurve('y = pi*sin(x)') curve.attach(self) curve.setPen(qt.QPen(qt.Qt.green, 2)) curve.setData(x, y) # attach another curve curve = Qwt.QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2') curve.attach(self) curve.setPen(qt.QPen(qt.Qt.black, 2)) curve.setData(x, z) # attach a grid grid = Qwt.QwtPlotGrid() grid.attach(self) grid.setPen(qt.QPen(qt.Qt.black, 0, qt.Qt.DotLine)) # attach a horizontal marker at y = 0 marker = Qwt.QwtPlotMarker() marker.attach(self) marker.setValue(0.0, 0.0) marker.setLineStyle(Qwt.QwtPlotMarker.HLine) marker.setLabelAlignment(qt.Qt.AlignRight | qt.Qt.AlignTop) marker.setLabel(Qwt.QwtText('y = 0')) # attach a vertical marker at x = pi marker = Qwt.QwtPlotMarker() marker.attach(self) marker.setValue(pi, 0.0) marker.setLineStyle(Qwt.QwtPlotMarker.VLine) marker.setLabelAlignment(qt.Qt.AlignRight | qt.Qt.AlignBottom) marker.setLabel(Qwt.QwtText('x = pi')) # attach a plot image plotImage = PlotImage('Image') plotImage.attach(self) plotImage.setData(square(512, -2 * pi, 2 * pi), (-2 * pi, 2 * pi), (-2 * pi, 2 * pi)) self.connect(self, qt.SIGNAL("legendClicked(QwtPlotItem*)"), self.toggleVisibility) # replot self.replot() self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.canvas()) self.zoomer.setRubberBandPen(qt.QPen(qt.Qt.green))