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
class NewGraph(): def __init__(self): self.curves = [] self.titleFont = QFont("Helvetica", 12, QFont.Bold) self.axisFont = QFont("Helvetica", 11, QFont.Bold) def createGraph(self): self.plot = QwtPlot() self.plot.resize(1000, 1000) self.plot.setAxisScaleDraw(QwtPlot.xBottom, DateTimeTimeScaleDraw(names=False)) self.plot.replot() self.plot.show() def createCurve(self, x, y, colour): curve = QwtPlotCurve() colour = QColor(colour) curve.setPen(colour) curve.setData(x, y) curve.attach(self.plot) #self.plot.replot() self.curves.append(curve) def removeCurve(self, curveIndex): self.curves[curveIndex].attach(0) del self.curves[curveIndex] def setAxisTitles(self, yAxis, xAxis): # Create text for graph and axis titles xTitle = QwtText() xTitle.setText(xAxis) xTitle.setFont(self.axisFont) yTitle = QwtText() yTitle.setText(yAxis) yTitle.setFont(self.axisFont) self.plot.setAxisTitle(self.plot.yLeft, yTitle) self.plot.setAxisTitle(self.plot.xBottom, xTitle) def setTitle(self, title): titleText = QwtText() titleText.setText(title) titleText.setFont(self.titleFont) self.plot.setTitle(titleText)
def make(): # create a plot with a white canvas demo = QwtPlot(QwtText("Curve 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 = numpy.zeros(20, numpy.float32) y = numpy.zeros(20, numpy.float32) symbol_sizes = numpy.zeros(20, numpy.int32) symbolList = [] for i in range(20): x[i] = 1.0 * i y[i] = 2.0 * i symbol_sizes[i] = 3 + i if i % 2 == 0: symbolList.append( QwtSymbol(QwtSymbol.UTriangle, QBrush(Qt.black), QPen(Qt.black), QSize(3 + i, 3 + i))) else: symbolList.append( QwtSymbol(QwtSymbol.DTriangle, QBrush(Qt.red), QPen(Qt.red), QSize(3 + i, 3 + i))) curve = QwtPlotCurveSizes(x=x, y=y, symbolSizes=symbol_sizes) x = x + 10 curve1 = QwtPlotCurveSizes(x=x, y=y, symbolSizes=symbol_sizes) curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.black), QPen(Qt.black), QSize(5, 5))) curve.setPen(QPen(Qt.blue, 2)) curve1.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.red), QSize(10, 10))) curve1.setPen(QPen(Qt.blue, 2)) curve1.setSymbolList(symbolList) curve.attach(demo) curve1.attach(demo) demo.resize(640, 480) demo.show() return demo
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 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
# -*- coding: utf-8 -*- __author__ = 'Valeriy' from qwt.qt.QtGui import QApplication from qwt import QwtPlot, QwtPlotCurve import numpy as np app = QApplication([]) # x = [1,2,3,4,5,6,7,8,9] # y1 = [3.2, 5.1 ,7.0, 4.24, 4.41, 8.34, 2.21, 5.657, 6.1] x = [] y1 = [] my_plot = QwtPlot("Two curves") curve1 = QwtPlotCurve("Curve 1") my_plot.resize(600, 300) curve1.setData(x, y1) curve1.attach(my_plot) # my_plot.replot() my_plot.show() app.exec_() # SELECT PrepData FROM= Pdata WHERE ((PNameId=2) AND (SNameId = 14) AND (YearId=2012))
class FermentGraph(QWidget): _logname = 'FermentGraphGeneric' _log = logging.getLogger(f'{_logname}') def __init__(self, database, parent=None): super().__init__(parent) self.db = database self.updateTimer = QTimer(self) self.updateTimer.start(5000) self.plot = QwtPlot() self.curve = QwtPlotCurve() self.curve.attach(self.plot) self.plot.resize(1000, 1000) self.plot.show() self.plot.setAxisScaleDraw(QwtPlot.xBottom, DateTimeTimeScaleDraw()) axisFont = QFont("Helvetica", 11, QFont.Bold) titleFont = QFont("Helvetica", 12, QFont.Bold) xTitle = QwtText() xTitle.setText("Time") xTitle.setFont(axisFont) self.plot.setAxisTitle(self.plot.xBottom, xTitle) self.yTitle = QwtText() self.yTitle.setFont(axisFont) self.plot.setAxisTitle(self.plot.yLeft, self.yTitle) self.titleText = QwtText() self.titleText.setFont(titleFont) self.plot.setTitle(self.titleText) mainLayout = QHBoxLayout() mainLayout.addWidget(self.plot) self.setLayout(mainLayout) self.plot.show() self.results = [] self.batchID = None def updatePlot(self, variable): if self.batchID is not None: self.db.flushTables() sql = f"SELECT TimeStamp, {variable} FROM Ferment WHERE BatchID = '{self.batchID}'" timestamps = [] self.results = [] for data in self.db.custom(sql)[1:]: timestamps.append(data[0]) self.results.append(data[1]) startTime = timestamps[0] for i in range(len(timestamps)): timestamps[i] = (timestamps[i] - startTime).seconds # self.plot.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw()) self.curve.setData(timestamps, self.results) self.plot.replot() self.plot.show() def changeTank(self, tankID): self.titleText.setText(f"Fermentation Tank: {tankID}")
pen.setJoinStyle(Qt.MiterJoin) symbol = QwtSymbol() symbol.setPen(pen) symbol.setBrush(Qt.red) symbol.setPath(path) symbol.setPinPoint(QPointF(0.0, 0.0)) symbol.setSize(10, 14) # --- Test it within a simple plot --- curve = QwtPlotCurve() curve_pen = QPen(Qt.blue) curve_pen.setStyle(Qt.DotLine) curve.setPen(curve_pen) curve.setSymbol(symbol) x = np.linspace(0, 10, 10) curve.setData(x, np.sin(x)) plot = QwtPlot() curve.attach(plot) plot.resize(600, 300) plot.replot() plot.show() plot.grab().save( osp.join(osp.abspath(osp.dirname(__file__)), "images", "symbol_path_example.png")) app.exec_()
class TabGraph(QWidget): _logname = 'TabGraph' _log = logging.getLogger(f'{_logname}') ##TabGraph constructor # #Create the graph and accompanying buttons def __init__(self, db, parent=None): super().__init__(parent) # self.LOGIN = LOGIN # self.db = dataBase(self.LOGIN, "Brewing") self.db = db self.dataY = np.zeros(0) self.dataX = np.linspace(0, len(self.dataY), len(self.dataY)) self.count = 0 self.timeLabel = QLabel("Timer:") self.timeLabel.setAlignment(QtCore.Qt.AlignRight) self.tempLabel = QLabel("Temp:") self.tempLabel.setAlignment(QtCore.Qt.AlignRight) self.targetTemp = QLabel("Set Temp:") self.targetTime = QLabel("Set Time:") self.targetTimeLabel = QLabel("Target: ") self.targetTimeLabel.setAlignment(QtCore.Qt.AlignRight) self.targetTempLabel = QLabel("Target: ") self.targetTempLabel.setAlignment(QtCore.Qt.AlignRight) self.startButton = QPushButton() self.stopButton = QPushButton() self.plot = QwtPlot() self.curve = QwtPlotCurve() self.curve.attach(self.plot) self.plot.resize(1000, 1000) self.plot.replot() self.plot.show() axisFont = QFont("Helvetica", 11, QFont.Bold) titleFont = QFont("Helvetica", 12, QFont.Bold) xTitle = QwtText() xTitle.setText("Time") xTitle.setFont(axisFont) self.plot.setAxisTitle(self.plot.xBottom, xTitle) yTitle = QwtText() yTitle.setText(f"Temperature {DEGREESC}") yTitle.setFont(axisFont) self.plot.setAxisTitle(self.plot.yLeft, yTitle) self.tempStatusLED = QLed(self, onColour=QLed.Green, offColour=QLed.Red, shape=QLed.Circle) self.tempStatusLED.value = False self.tempStatusLED.setMaximumSize(25, 25) self.timeStatusLED = QLed(self, onColour=QLed.Green, offColour=QLed.Red, shape=QLed.Circle) self.timeStatusLED.value = False self.timeStatusLED.setMaximumSize(25, 25) self.recipeGrid = QGridLayout() self.recipeGrid.addWidget(QLabel(f"Recipe:"), 0, 0) self.recipeGrid.addWidget(QLabel(f"{self.recipedata['recipeName']}"), 0, 1) self.recipeGrid.addWidget(QHLine(), 1, 0, 1, 2) self.recipeGrid.addWidget(self.targetTemp) self.recipeGrid.addWidget(self.targetTempLabel) self.recipeGrid.addWidget(self.targetTime) self.recipeGrid.addWidget(self.targetTimeLabel) self.recipeGrid.addWidget(QHLine(), 4, 0, 1, 2) self.tempLayout = QHBoxLayout() # self.tempLayout.addWidget(self.targetTempLabel) # self.tempLayout.addStretch(10) self.tempLayout.addWidget(self.tempLabel) # self.tempLayout.addStretch(10) self.tempLayout.addWidget(self.tempStatusLED) self.tempLayout.addStretch(10) self.timeLayout = QHBoxLayout() # self.timeLayout.addWidget(self.targetTimeLabel) # self.timeLayout.addStretch(10) self.timeLayout.addWidget(self.timeLabel) # self.timeLayout.addStretch(10) self.timeLayout.addWidget(self.timeStatusLED) self.timeLayout.addStretch(10) self.plotLayout = QVBoxLayout() self.plotLayout.addLayout(self.timeLayout) # self.plotLayout.addStretch(10) self.plotLayout.addLayout(self.tempLayout) # self.plotLayout.addStretch(10) self.plotLayout.addWidget(self.plot) self.buttonLayout = QVBoxLayout() self.buttonLayout.addWidget(self.startButton) self.buttonLayout.addWidget(self.stopButton) self.buttonLayout.addLayout(self.recipeGrid) self.buttonLayout.addStretch(100) mainLayout = QHBoxLayout() mainLayout.addLayout(self.buttonLayout) mainLayout.addLayout(self.plotLayout) vLayout = QVBoxLayout(self) vLayout.addLayout(mainLayout) self.minuteTimer = QTimer(self) self.minuteTimer.timeout.connect(lambda: self.addTimer(60)) ##Keep track of the timer def addTimer(self, seconds): self.count += seconds ##convery the time from seconds to hours/minutes def display_time(self, seconds, granularity=2): result = [] for name, count in TIME_INTERVALS: value = seconds // count if value: seconds -= value * count if value == 1: name = name.rstrip('s') result.append("{} {}".format(value, name)) return ', '.join(result[:granularity])
from qwt.qt.QtGui import QApplication from qwt import QwtPlot, QwtPlotCurve import numpy as np app = QApplication([]) x = np.linspace(-10, 10, 500) y1, y2 = np.cos(x), np.sin(x) my_plot = QwtPlot("Two curves") curve1, curve2 = QwtPlotCurve("Curve 1"), QwtPlotCurve("Curve 2") curve1.setData(x, y1) curve2.setData(x, y2) curve1.attach(my_plot) curve2.attach(my_plot) my_plot.resize(600, 300) my_plot.replot() my_plot.show() app.exec_()