def __init__(self, *args): colors = [ Qt.red, Qt.darkRed, Qt.green, Qt.darkGreen, Qt.blue, Qt.darkBlue, Qt.cyan, Qt.darkCyan, Qt.magenta, Qt.darkMagenta, Qt.yellow, Qt.darkYellow, Qt.gray, Qt.darkGray, Qt.lightGray, Qt.black ] QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.white) self.alignScales() # grid self.grid = QwtPlotGrid() self.grid.attach(self) self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # set titles self.setTitle("Gráfico") self.setAxisTitle(QwtPlot.xBottom, 'Tempo [hh:mm:ss] -->') self.setAxisTitle(QwtPlot.yLeft, 'Nível [mm] -->') """Habilita e denomina eixo Y2""" self.enableAxis(QwtPlot.yRight) self.setAxisTitle(QwtPlot.yRight, '<-- Temp. [ºC]') self.nplots = 16 self.Plots = np.array([]) self.Data = np.array([]) for i in range(self.nplots): self.Plots = np.append(self.Plots, QwtPlotCurve()) self.Plots[i].setPen(QPen(colors[i])) self.Plots[i].attach(self) """define como valor plotado será escrito no eixo x""" self.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw()) self.Data = np.append(self.Data, dataclass()) """Os índices pares se referem à plots no eixo Y1, e os índices ímpares são ligados ao eixo Y2""" if divmod(i, 2)[1] == 1: self.Plots[i].setYAxis(QwtPlot.yRight) self.Plots[i].setData(self.Data[i].x, self.Data[i].y) # legend #self.legend = QwtLegend #QwtLegend().setFrameStyle(QFrame.Box) #self.insertLegend(QwtLegend().setFrameStyle(QFrame.Box), QwtPlot.BottomLegend) self.insertLegend(QwtLegend(), QwtPlot.BottomLegend) # replot self.replot() # zoom # self.zoomer = QwtPlotZoomer(QwtPlot.xBottom, # QwtPlot.yLeft, # QwtPicker.DragSelection, # QwtPicker.AlwaysOn, # self.canvas()) # # self.zoomer.setRubberBandPen(QPen(Qt.green)) self.startTimer(50)
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setTitle('Cartesian Coordinate System Demo') # create a plot with a white canvas self.setCanvasBackground(Qt.white) # set plot layout self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(True) # attach a grid grid = QwtPlotGrid() grid.attach(self) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # attach a x-axis xaxis = CartesianAxis(QwtPlot.xBottom, QwtPlot.yLeft) xaxis.attach(self) self.enableAxis(QwtPlot.xBottom, False) # attach a y-axis yaxis = CartesianAxis(QwtPlot.yLeft, QwtPlot.xBottom) yaxis.attach(self) self.enableAxis(QwtPlot.yLeft, False) # calculate 3 NumPy arrays x = np.arange(-2*np.pi, 2*np.pi, 0.01) y = np.pi*np.sin(x) z = 4*np.pi*np.cos(x)*np.cos(x)*np.sin(x) # attach a curve curve = QwtPlotCurve('y = pi*sin(x)') curve.attach(self) curve.setPen(QPen(Qt.green, 2)) curve.setData(x, y) # attach another curve curve = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2') curve.attach(self) curve.setPen(QPen(Qt.black, 2)) curve.setData(x, z) self.replot()
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = QwtPlot(self) self.plot.setTitle("A Simple Map Demonstration") self.plot.setCanvasBackground(Qt.white) self.plot.setAxisTitle(QwtPlot.xBottom, "x") self.plot.setAxisTitle(QwtPlot.yLeft, "y") self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0) self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0) self.setCentralWidget(self.plot) # Initialize map data self.count = self.i = 1000 self.xs = np.zeros(self.count, np.float) self.ys = np.zeros(self.count, np.float) self.kappa = 0.2 self.curve = QwtPlotCurve("Map") self.curve.attach(self.plot) self.curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue), QSize(5, 5))) self.curve.setPen(QPen(Qt.cyan)) toolBar = QToolBar(self) self.addToolBar(toolBar) # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz) self.ticks = 10 self.tid = self.startTimer(self.ticks) self.timer_tic = None self.user_tic = None self.system_tic = None self.plot.replot()
def make(): demo = QwtPlot() demo.setCanvasBackground(Qt.white) demo.setTitle("Histogram") grid = QwtPlotGrid() grid.enableXMin(True) grid.enableYMin(True) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) grid.setMinorPen(QPen(Qt.gray, 0, Qt.DotLine)) grid.attach(demo) histogram = HistogramItem() histogram.setColor(Qt.darkCyan) numValues = 20 samples = [] pos = 0.0 for i in range(numValues): width = 5 + random.randint(0, 4) value = random.randint(0, 99) samples.append(QwtIntervalSample(value, QwtInterval(pos, pos + width))) pos += width histogram.setData(QwtIntervalSeriesData(samples)) histogram.attach(demo) demo.setAxisScale(QwtPlot.yLeft, 0.0, 100.0) demo.setAxisScale(QwtPlot.xBottom, 0.0, pos) demo.replot() demo.resize(600, 400) demo.show() return demo
def make(): # create a plot with a white canvas demo = QwtPlot(QwtText("Errorbar Demonstation")) demo.setCanvasBackground(Qt.white) demo.plotLayout().setAlignCanvasToScales(True) grid = QwtPlotGrid() grid.attach(demo) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # calculate data and errors for a curve with error bars x = np.arange(0, 10.1, 0.5, np.float) y = np.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=QPen(Qt.black, 2), curveSymbol=QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.black, 2), QSize(9, 9)), errorPen=QPen(Qt.blue, 2), errorCap=10, errorOnTop=errorOnTop, ) curve.attach(demo) demo.resize(640, 480) demo.show() return demo
def __init__(self): self.xEnabled = True self.yEnabled = True self.xMinEnabled = False self.yMinEnabled = False self.xScaleDiv = QwtScaleDiv() self.yScaleDiv = QwtScaleDiv() self.majorPen = QPen() self.minorPen = QPen()
def __init__(self, x=[], y=[], dx=None, dy=None, curvePen=None, curveStyle=None, curveSymbol=None, errorPen=None, 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. """ QwtPlotCurve.__init__(self) if curvePen is None: curvePen = QPen(Qt.NoPen) if curveStyle is None: curveStyle = QwtPlotCurve.Lines if curveSymbol is None: curveSymbol = QwtSymbol() if errorPen is None: errorPen = QPen(Qt.NoPen) 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 __insertCurve(self, orientation, color, base): curve = QwtPlotCurve() curve.attach(self) curve.setPen(QPen(color)) curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.gray), QPen(color), QSize(8, 8))) fixed = base * np.ones(10, np.float) changing = np.arange(0, 95.0, 10.0, np.float) + 5.0 if orientation == Qt.Horizontal: curve.setData(changing, fixed) else: curve.setData(fixed, changing)
def __init__(self, *args): QwtPlot.__init__(self, *args) # Initialize Decice address, #self.uut_dev = GPIBdevice.GPIBdevice(args[0]) self.rm = visa.ResourceManager() print(self.rm.list_resources()) self.uut_dev = self.rm.open_resource(args[0]) print('open pass') # Initialize 坐标轴 self.setCanvasBackground(Qt.white) self.alignScales() grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) self.setAxisScale(QwtPlot.xBottom, 0.0, 300.1, 10.0) self.setAxisAutoScale(QwtPlot.yLeft, True) #self.setAxisScale(QwtPlot.yLeft,4.0,20.0,2.0) self.x = np.arange( 0.0, 300.1, 0.5 ) #0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms self.z = np.zeros(len(self.x), np.float) self.setTitle("UUT Reading Monitor") self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.curveL = QwtPlotCurve("UUT Reading") self.curveL.attach(self) self.curveL.setPen(QPen(Qt.red)) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading") self.replot() self.startTimer(500) #ms# FOR GET READING self.starttime = time.clock() #unit: s self.idx = 0 self.readfmt = "%.8f" self.Saveinfo("Starting...") IDN = self.uut_get_val(self.uut_dev, "*IDN?\r") print IDN print "Starting..."
def __init__(self, *args): QwtPlot.__init__(self, *args) # make a QwtPlot widget self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(1) self.setTitle('QwtImagePlot: (un)zoom & (un)hide') # set axis titles self.setAxisTitle(QwtPlot.xBottom, 'time (s)') self.setAxisTitle(QwtPlot.yLeft, 'frequency (Hz)') # insert a few curves self.cSin = QwtPlotCurve('y = pi*sin(x)') self.cCos = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2') self.cSin.attach(self) self.cCos.attach(self) # set curve styles self.cSin.setPen(QPen(Qt.green, 2)) self.cCos.setPen(QPen(Qt.black, 2)) self.xzoom_loc = None self.yzoom_loc = None self.xpos = None self.ypos = None # attach a grid grid = QwtPlotGrid() grid.attach(self) grid.setPen(Qt.black, 0, Qt.DotLine) # create zoom curve self.zoom_outline = QwtPlotCurve() self.zoom_outline.setStyle(QwtPlotCurve.Lines) # create and initialize an image display self.plotImage = QwtPlotImage(self) self.plotImage.attach(self) self.gain = 2.0 self.updateDisplay() self.zoomStack = [] self.spy = Spy(self.canvas()) self.prev_xpos = None self.prev_ypos = None # self.connect(self, Qt.SIGNAL("legendClicked(QwtPlotItem*)"), # self.toggleVisibility) self.spy.MouseMove.connect(self.onmouseMoveEvent) self.spy.MousePress.connect(self.onmousePressEvent) self.spy.MouseRelease.connect(self.onmouseReleaseEvent)
def drawBar(self, painter, orientation, rect): painter.save() color = painter.pen().color() r = rect.normalized() factor = 125 light = color.lighter(factor) dark = color.darker(factor) painter.setBrush(color) painter.setPen(Qt.NoPen) QwtPainter.drawRect(painter, r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2) painter.setBrush(Qt.NoBrush) painter.setPen(QPen(light, 2)) QwtPainter.drawLine(painter, r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2) painter.setPen(QPen(dark, 2)) QwtPainter.drawLine(painter, r.left() + 1, r.bottom(), r.right() + 1, r.bottom()) painter.setPen(QPen(light, 1)) QwtPainter.drawLine(painter, r.left(), r.top() + 1, r.left(), r.bottom()) QwtPainter.drawLine(painter, r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1) painter.setPen(QPen(dark, 1)) QwtPainter.drawLine(painter, r.right() + 1, r.top() + 1, r.right() + 1, r.bottom()) QwtPainter.drawLine(painter, r.right(), r.top() + 2, r.right(), r.bottom() - 1) painter.restore()
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol): size = symbol.size() off = 0 pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) off = 1 painter.setPen(pen) if QwtPainter.roundingAlignment(painter): sw = np.floor(size.width()) sh = np.floor(size.height()) sw2 = size.width() // 2 sh2 = size.height() // 2 for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x - sw2 x2 = x1 + sw + off y1 = y - sh2 y2 = y1 + sh + off QwtPainter.drawLine(painter, x1, y1, x2, y2) QwtPainter.drawLine(painter, x2, y1, x1, y2) else: sw = size.width() sh = size.height() sw2 = .5 * size.width() sh2 = .5 * size.height() for pos in points: x1 = pos.x() - sw2 x2 = x1 + sw y1 = pos.y() - sh2 y2 = y1 + sh QwtPainter.drawLine(painter, x1, y1, x2, y2) QwtPainter.drawLine(painter, x2, y1, x1, y2)
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) if QwtPainter.roundingAlignment(painter): for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x - size.width() // 2 y1 = y - size.height() // 2 x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(x, y1) polygon += QPointF(x1, y) polygon += QPointF(x, y2) polygon += QPointF(x2, y) QwtPainter.drawPolygon(painter, polygon) else: for pos in points: x1 = pos.x() - .5 * size.width() y1 = pos.y() - .5 * size.height() x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(pos.x(), y1) polygon += QPointF(x1, pos.y()) polygon += QPointF(pos.x(), y2) polygon += QPointF(x2, pos.y()) QwtPainter.drawPolygon(painter, polygon)
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) doAlign = QwtPainter.roundingAlignment(painter) sw2 = .5 * size.width() sh2 = .5 * size.height() if doAlign: sw2 = np.floor(sw2) sh2 = np.floor(sh2) for pos in points: x = pos.x() y = pos.y() if doAlign: x = round(x) y = round(y) x1 = x - sw2 x2 = x1 + size.width() y1 = y - sh2 y2 = y1 + size.height() if type == QwtTriangle.Left: triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)] elif type == QwtTriangle.Right: triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)] elif type == QwtTriangle.Up: triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)] elif type == QwtTriangle.Down: triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)] QwtPainter.drawPolygon(painter, QPolygonF(triangle))
def qwtDrawRectSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) painter.setRenderHint(QPainter.Antialiasing, False) if QwtPainter.roundingAlignment(painter): sw = size.width() sh = size.height() sw2 = size.width() // 2 sh2 = size.height() // 2 for pos in points: x = round(pos.x()) y = round(pos.y()) r = QRectF(x - sw2, y - sh2, sw, sh) QwtPainter.drawRect(painter, r) else: sw = size.width() sh = size.height() sw2 = .5 * size.width() sh2 = .5 * size.height() for pos in points: x = pos.x() y = pos.y() r = QRectF(x - sw2, y - sh2, sw, sh) QwtPainter.drawRect(painter, r)
def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle): """ Draw a round frame :param QPainter painter: Painter :param QRectF rect: Target rectangle :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders :param int lineWidth: Line width :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow` """ Plain, Sunken, Raised = list(range(3)) style = Plain if (frameStyle & QFrame.Sunken) == QFrame.Sunken: style = Sunken elif (frameStyle & QFrame.Raised) == QFrame.Raised: style = Raised lw2 = .5 * lineWidth r = rect.adjusted(lw2, lw2, -lw2, -lw2) if style != Plain: c1 = palette.color(QPalette.Light) c2 = palette.color(QPalette.Dark) if style == Sunken: c1, c2 = c2, c1 gradient = QLinearGradient(r.topLeft(), r.bottomRight()) gradient.setColorAt(0., c1) gradient.setColorAt(1., c2) brush = QBrush(gradient) else: brush = palette.brush(QPalette.WindowText) painter.save() painter.setPen(QPen(brush, lineWidth)) painter.drawEllipse(r) painter.restore()
def __init__(self, *args): QwtPlot.__init__(self, *args) self.curves = {} self.data = {} self.timeData = 1.0 * np.arange(0, HISTORY, 1) self.MemStat = MemStat() self.setAutoReplot(False) self.plotLayout().setAlignCanvasToScales(True) self.setAxisScale(QwtPlot.xBottom, HISTORY, 0) self.setAxisScale(QwtPlot.yLeft, 0, 100) self.setAxisLabelAlignment(QwtPlot.xBottom, Qt.AlignLeft | Qt.AlignBottom) grid = QwtPlotGrid() grid.enableXMin(True) grid.enableYMin(True) grid.setMajPen(QPen(Qt.black, 0, Qt.DotLine)) grid.setMinPen(QPen(Qt.gray, 0, Qt.DotLine)) grid.attach(self) stat = MemStat.statistic() self.data["MemTotal"] = np.zeros(HISTORY, float) self.data["MemFree"] = np.zeros(HISTORY, float) self.data["SwapTotal"] = np.zeros(HISTORY, float) self.data["SwapFree"] = np.zeros(HISTORY, float) curve = MemoryCurve("Memory") curve.setColor(self.colors[0]) curve.attach(self) self.curves["Memory"] = curve self.data["Memory"] = np.zeros(HISTORY, float) curve = MemoryCurve("Swap") curve.setColor(self.colors[1]) curve.attach(self) self.curves["Swap"] = curve self.data["Swap"] = np.zeros(HISTORY, float) self.startTimer(1000) self.replot()
def __init__(self, size): super(QwtStyleSheetRecorder, self).__init__() self.__size = size self.__pen = QPen() self.__brush = QBrush() self.__origin = QPointF() self.clipRects = [] self.border = Border() self.background = Background()
def __init__(self): QwtPlotItem_PrivateData.__init__(self) self.style = QwtPlotCurve.Lines self.baseline = 0. self.symbol = None self.attributes = 0 self.legendAttributes = QwtPlotCurve.LegendShowLine self.pen = QPen(Qt.black) self.brush = QBrush()
def __init__(self): self.labelAlignment = Qt.AlignCenter self.labelOrientation = Qt.Horizontal self.spacing = 2 self.symbol = None self.style = QwtPlotMarker.NoLine self.xValue = 0. self.yValue = 0. self.label = QwtText() self.pen = QPen()
def __init__(self, *args): QwtPlot.__init__(self, *args) self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.enableAxis(self.xBottom) # insert a few curves self.Alpha = QwtPlotCurve('Alpha') self.Alpha.setPen(QPen(Qt.red)) self.Alpha.attach(self) self.Epsilon = QwtPlotCurve('Epsilon') self.Epsilon.setPen(QPen(Qt.blue)) self.Epsilon.attach(self) # initialize the data self.Alpha.setData([0], [0]) self.Epsilon.setData([0], [0]) # replot self.replot()
def params(self, *args): symbols, = args symb1 = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue), QSize(5, 5)) symb2 = QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta), QSize(5, 5)) if symbols: return ( ('Sticks', symb1), ('Lines', symb1), ('Steps', symb2), ('Dots', symb2), ) else: return ( ('Sticks', None), ('Lines', None), ('Steps', None), ('Dots', None), )
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setTitle('ReallySimpleDemo.py') self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.setAxisTitle(QwtPlot.xBottom, 'x -->') self.setAxisTitle(QwtPlot.yLeft, 'y -->') self.enableAxis(self.xBottom) # insert a few curves cSin = QwtPlotCurve('y = sin(x)') cSin.setPen(QPen(Qt.red)) cSin.attach(self) cCos = QwtPlotCurve('y = cos(x)') cCos.setPen(QPen(Qt.blue)) cCos.attach(self) # make a Numeric array for the horizontal data x = np.arange(0.0, 10.0, 0.1) # initialize the data cSin.setData(x, np.sin(x)) cCos.setData(x, np.cos(x)) # insert a horizontal marker at y = 0 mY = QwtPlotMarker() mY.setLabel(QwtText('y = 0')) mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mY.setLineStyle(QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) # insert a vertical marker at x = 2 pi mX = QwtPlotMarker() mX.setLabel(QwtText('x = 2 pi')) mX.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mX.setLineStyle(QwtPlotMarker.VLine) mX.setXValue(2 * np.pi) mX.attach(self) # replot self.replot()
def __init__(self): QwtPlotItem_PrivateData.__init__(self) self.style = QwtPlotCurve.Lines self.baseline = 0. self.symbol = None self.attributes = 0 self.paintAttributes = QwtPlotCurve.FilterPoints #TODO: uncomment next line when QwtClipper will be implemented # self.paintAttributes = QwtPlotCurve.ClipPolygons|QwtPlotCurve.FilterPoints self.legendAttributes = QwtPlotCurve.LegendShowLine self.pen = QPen(Qt.black) self.brush = QBrush()
def __init__(self, *args): QFrame.__init__(self, *args) self.setFrameStyle(QFrame.Box | QFrame.Raised) self.setLineWidth(2) self.setMidLineWidth(3) p = QPalette() p.setColor(self.backgroundRole(), QColor(30, 30, 50)) self.setPalette(p) # make curves and maps self.tuples = [] # curve 1 curve = QwtPlotCurve() curve.setPen(QPen(QColor(150, 150, 200), 2)) curve.setStyle(QwtPlotCurve.Lines) curve.setSymbol(QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.yellow, 2), QSize(7, 7))) self.tuples.append((curve, QwtScaleMap(0, 100, -1.5, 1.5), QwtScaleMap(0, 100, 0.0, 2*np.pi))) # curve 2 curve = QwtPlotCurve() curve.setPen(QPen(QColor(200, 150, 50), 1, Qt.DashDotDotLine)) curve.setStyle(QwtPlotCurve.Sticks) curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.blue), QPen(Qt.yellow), QSize(5, 5))) self.tuples.append((curve, QwtScaleMap(0, 100, 0.0, 2*np.pi), QwtScaleMap(0, 100, -3.0, 1.1))) # curve 3 curve = QwtPlotCurve() curve.setPen(QPen(QColor(100, 200, 150))) curve.setStyle(QwtPlotCurve.Lines) self.tuples.append((curve, QwtScaleMap(0, 100, -1.1, 3.0), QwtScaleMap(0, 100, -1.1, 3.0))) # curve 4 curve = QwtPlotCurve() curve.setPen(QPen(Qt.red)) curve.setStyle(QwtPlotCurve.Lines) self.tuples.append((curve, QwtScaleMap(0, 100, -5.0, 1.1), QwtScaleMap(0, 100, -1.1, 5.0))) # data self.phase = 0.0 self.base = np.arange(0.0, 2.01*np.pi, 2*np.pi/(USize-1)) self.uval = np.cos(self.base) self.vval = np.sin(self.base) self.uval[1::2] *= 0.5 self.vval[1::2] *= 0.5 self.newValues() # start timer self.tid = self.startTimer(250)
def __init__(self, *args): QFrame.__init__(self, *args) self.xMap = QwtScaleMap() self.xMap.setScaleInterval(-0.5, 10.5) self.yMap = QwtScaleMap() self.yMap.setScaleInterval(-1.1, 1.1) # frame style self.setFrameStyle(QFrame.Box | QFrame.Raised) self.setLineWidth(2) self.setMidLineWidth(3) # calculate values self.x = np.arange(0, 10.0, 10.0 / 27) self.y = np.sin(self.x) * np.cos(2 * self.x) # make curves with different styles self.curves = [] self.titles = [] # curve 1 self.titles.append('Style: Sticks, Symbol: Ellipse') curve = QwtPlotCurve() curve.setPen(QPen(Qt.red)) curve.setStyle(QwtPlotCurve.Sticks) curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue), QSize(5, 5))) self.curves.append(curve) # curve 2 self.titles.append('Style: Lines, Symbol: None') curve = QwtPlotCurve() curve.setPen(QPen(Qt.darkBlue)) curve.setStyle(QwtPlotCurve.Lines) self.curves.append(curve) # curve 3 self.titles.append('Style: Lines, Symbol: None, Antialiased') curve = QwtPlotCurve() curve.setPen(QPen(Qt.darkBlue)) curve.setStyle(QwtPlotCurve.Lines) curve.setRenderHint(QwtPlotItem.RenderAntialiased) self.curves.append(curve) # curve 4 self.titles.append('Style: Steps, Symbol: None') curve = QwtPlotCurve() curve.setPen(QPen(Qt.darkCyan)) curve.setStyle(QwtPlotCurve.Steps) self.curves.append(curve) # curve 5 self.titles.append('Style: NoCurve, Symbol: XCross') curve = QwtPlotCurve() curve.setStyle(QwtPlotCurve.NoCurve) curve.setSymbol( QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta), QSize(5, 5))) self.curves.append(curve) # attach data, using Numeric for curve in self.curves: curve.setData(self.x, self.y)
def main(args): app = QApplication(args) demo = QwtPlot() grid = QwtPlotGrid() grid.attach(demo) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) grid.enableX(True) grid.enableY(True) complex_divider = 50.0 myXScale = ComplexScaleDraw(start_value=0.0, end_value=complex_divider) #print('myXScale', myXScale) demo.setAxisScaleDraw(QwtPlot.xBottom, myXScale) m = QwtPlotMarker() m.attach(demo) m.setValue(complex_divider, 0.0) m.setLineStyle(QwtPlotMarker.VLine) m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) m.setLinePen(QPen(Qt.black, 2, Qt.SolidLine)) vector_array = numpy.zeros((100, ), numpy.float32) for i in range(100): vector_array[i] = i curve = QwtPlotCurve('example data') curve.attach(demo) x_array = numpy.zeros(100, numpy.float32) y_array = numpy.zeros(100, numpy.float32) for i in range(100): x_array[i] = 1.0 * i y_array[i] = 2.0 * i curve.setSamples(x_array, y_array) demo.resize(600, 400) demo.replot() demo.show() # app.setMainWidget(demo) app.exec_()
def __init__(self, *args): QWidget.__init__(self, *args) layout = QGridLayout(self) # try to create a plot for SciPy arrays # make a curve and copy the data numpy_curve = QwtPlotCurve('y = lorentzian(x)') x = np.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 = QwtPlot(self) numpy_plot.setTitle('numpy array') numpy_plot.setCanvasBackground(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(QPen(Qt.red)) layout.addWidget(numpy_plot, 0, 0) numpy_plot.replot() # create a plot widget for lists of Python floats list_plot = QwtPlot(self) list_plot.setTitle('Python list') list_plot.setCanvasBackground(Qt.white) list_plot.plotLayout().setCanvasMargin(0) list_plot.plotLayout().setAlignCanvasToScales(True) x = drange(0.0, 10.0, 0.01) y = [lorentzian(item) for item in x] # insert a curve, make it red and copy the lists list_curve = QwtPlotCurve('y = lorentzian(x)') list_curve.attach(list_plot) list_curve.setPen(QPen(Qt.red)) list_curve.setData(x, y) layout.addWidget(list_plot, 0, 1) layout.addWidget(DataPlot(self),1,1) layout.addWidget(3dstl(self), 1, 0) list_plot.replot()
def setMajorPen(self, *args): if len(args) == 3: color, width, style = args self.setMajorPen(QPen(color, width, style)) elif len(args) == 1: pen, = args if self.__data.majorPen != pen: self.__data.majorPen = pen self.legendChanged() self.itemChanged() else: raise TypeError("%s().setMajorPen() takes 1 or 3 argument(s) (%s "\ "given)" % (self.__class__.__name__, len(args)))
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.white) self.alignScales() # Initialize data self.x = np.arange(0.0, 100.1, 0.5) self.y = np.zeros(len(self.x), np.float) self.z = np.zeros(len(self.x), np.float) self.setTitle("A Moving QwtPlot Demonstration") self.insertLegend(QwtLegend(), QwtPlot.BottomLegend); self.curveR = QwtPlotCurve("Data Moving Right") self.curveR.attach(self) self.curveL = QwtPlotCurve("Data Moving Left") self.curveL.attach(self) self.curveL.setSymbol(QwtSymbol(QwtSymbol.Ellipse, QBrush(), QPen(Qt.yellow), QSize(7, 7))) self.curveR.setPen(QPen(Qt.red)) self.curveL.setPen(QPen(Qt.blue)) mY = QwtPlotMarker() mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mY.setLineStyle(QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "Values") self.startTimer(50) self.phase = 0.0