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 __init__(self, *args): QwtPlot.__init__(self, *args) self.setTitle("Interactive Plot") self.setCanvasColor(Qt.darkCyan) grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.white, 0, Qt.DotLine)) self.setAxisScale(QwtPlot.xBottom, 0.0, 100.0) self.setAxisScale(QwtPlot.yLeft, 0.0, 100.0) # Avoid jumping when label with 3 digits # appear/disappear when scrolling vertically scaleDraw = self.axisScaleDraw(QwtPlot.yLeft) scaleDraw.setMinimumExtent( scaleDraw.extent(self.axisWidget(QwtPlot.yLeft).font()) ) self.plotLayout().setAlignCanvasToScales(True) self.__insertCurve(Qt.Vertical, Qt.blue, 30.0) self.__insertCurve(Qt.Vertical, Qt.magenta, 70.0) self.__insertCurve(Qt.Horizontal, Qt.yellow, 30.0) self.__insertCurve(Qt.Horizontal, Qt.white, 70.0) self.replot() scaleWidget = self.axisWidget(QwtPlot.yLeft) scaleWidget.setMargin(10) self.__colorBar = ColorBar(Qt.Vertical, scaleWidget) self.__colorBar.setRange(QColor(Qt.red), QColor(Qt.darkBlue)) self.__colorBar.setFocusPolicy(Qt.TabFocus) self.__colorBar.colorSelected.connect(self.setCanvasColor) # we need the resize events, to lay out the color bar scaleWidget.installEventFilter(self) # we need the resize events, to lay out the wheel self.canvas().installEventFilter(self) scaleWidget.setWhatsThis( "Selecting a value at the scale will insert a new curve." ) self.__colorBar.setWhatsThis( "Selecting a color will change the background of the plot." ) self.axisWidget(QwtPlot.xBottom).setWhatsThis( "Selecting a value at the scale will insert a new curve." )
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) self.setTitle("Interactive Plot") self.setCanvasColor(Qt.darkCyan) grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.white, 0, Qt.DotLine)) self.setAxisScale(QwtPlot.xBottom, 0.0, 100.0) self.setAxisScale(QwtPlot.yLeft, 0.0, 100.0) # Avoid jumping when label with 3 digits # appear/disappear when scrolling vertically scaleDraw = self.axisScaleDraw(QwtPlot.yLeft) scaleDraw.setMinimumExtent(scaleDraw.extent( self.axisWidget(QwtPlot.yLeft).font())) self.plotLayout().setAlignCanvasToScales(True) self.__insertCurve(Qt.Vertical, Qt.blue, 30.0) self.__insertCurve(Qt.Vertical, Qt.magenta, 70.0) self.__insertCurve(Qt.Horizontal, Qt.yellow, 30.0) self.__insertCurve(Qt.Horizontal, Qt.white, 70.0) self.replot() scaleWidget = self.axisWidget(QwtPlot.yLeft) scaleWidget.setMargin(10) self.__colorBar = ColorBar(Qt.Vertical, scaleWidget) self.__colorBar.setRange( QColor(Qt.red), QColor(Qt.darkBlue)) self.__colorBar.setFocusPolicy(Qt.TabFocus) self.__colorBar.colorSelected.connect(self.setCanvasColor) # we need the resize events, to lay out the color bar scaleWidget.installEventFilter(self) # we need the resize events, to lay out the wheel self.canvas().installEventFilter(self) scaleWidget.setWhatsThis( 'Selecting a value at the scale will insert a new curve.') self.__colorBar.setWhatsThis( 'Selecting a color will change the background of the plot.') self.axisWidget(QwtPlot.xBottom).setWhatsThis( 'Selecting a value at the scale will insert a new curve.')
def __init__(self, *args): QwtPlot.__init__(self, *args) self.uut_dev = None self.timerId = None #self.interval = 250 # ms self.interval = config.interval # ms fileTIME = datetime.datetime.now() File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % ( fileTIME.year, fileTIME.month, fileTIME.day, fileTIME.hour, fileTIME.minute, fileTIME.second) self.fileNamme = '.\data\data_%s.txt' % File_timestamp print('Raw data record file name:%s' % self.fileNamme) # default parameters from config file self.x_ZERO = config.X_lower self.x_range = config.X_upper self.x_interval = config.X_grid_interval self.y_range_Upper = config.Y_upper self.y_range_Lower = config.Y_lower self.y_interval = config.Y_grid_interval self.unit = 'kPa' # default value, will replaced by actual reading. #self.getReadingCommand = r"UPPER_VAL?\r\n" # default pass and pac #self.getResp_rex = r'^[-]?([0-9]{1,}[.]?[0-9]*)' self.lenth = config.Slope_lenth # 40 = 10s caculate the slowrate # QwtPlot property # Initialize 坐标轴 self.setCanvasBackground(Qt.white) #Qt.white self.alignScales() grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) # x Axis property #self.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw(self.cpuStat.upTime())) #timeScale = QwtDateScaleDraw(Qt.LocalTime) #print(timeScale) #self.setAxisScaleDraw(QwtPlot.xBottom, timeScale) self.setAxisScale(QwtPlot.xBottom, 0.0, self.x_range, self.x_interval) #self.setAxisAutoScale(QwtPlot.yLeft,True) #self.setAxisScale(QwtPlot.yLeft,99.99,100.0,0.0005) self.setAxisScale(QwtPlot.yLeft, self.y_range_Lower, self.y_range_Upper, self.y_interval) self.setAxisLabelRotation(QwtPlot.xBottom, -45.0) self.x = np.arange( 0.0, self.x_range + 1, 0.25 ) #0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms #self.z = np.zeros(len(self.x), np.float) list = [] for i in range(len(self.x)): list.append(0.0) self.z = np.array(list) rlist = [] for i in range(self.lenth): # 10s rlist.append(0.0) self.RateList = np.array(rlist) self.setTitle("UUT Reading Monitor - OutPort(%s)\r\n" % (self.unit)) #self.insertLegend(QwtLegend(), QwtPlot.RightLegend); self.curveL = QwtPlotCurve("UUT Reading") self.curveL.attach(self) pen = QPen(Qt.red) pen.setWidth(1.5) #pen.setWidth(1) self.curveL.setPen(pen) font = QFont() font.setFamily("Calibri") #,Consolas font.setPointSize(16) # show the latest reading. line and point value self.peakMarker = m = QwtPlotMarker() m.setLineStyle(QwtPlotMarker.HLine) m.setLabelAlignment(Qt.AlignLeft | Qt.AlignTop) m.setLinePen(QPen(Qt.blue, 1.5, Qt.DashDotLine)) text = QwtText('Reading: ----') text.setColor(Qt.red) text.setBackgroundBrush(QBrush(self.canvasBackground())) text.setFont(font) m.setLabel(text) # MarkPoint symbol m.setSymbol( QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.blue), QPen(Qt.green), QSize(7, 7))) m.attach(self) # text marker , display slope rate self.txtMarker = m = QwtPlotMarker() m.setValue(self.x_range / 2, self.y_range_Upper - self.y_interval / 2) # show position m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) text = QwtText('Slope Rate: ----') text.setFont(font) text.setColor(Qt.white) text.setBackgroundBrush(QBrush(Qt.black)) text.setBorderPen(QPen(Qt.red, 2)) m.setLabel(text) m.attach(self) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading(%s)" % (self.unit)) self.replot() #self.startTimer(250)#ms# FOR GET READING #self.starttime = time.clock();#unit: s python2 self.starttime = time.time() # python3 self.idx = 0 self.readfmt = "%f" self.Saveinfo("Starting...")
def __init__(self, *args): QwtPlot.__init__(self, *args) self.uut_dev = None self.timerId = None self.interval = 250 # ms fileTIME = datetime.datetime.now() File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % (fileTIME.year,fileTIME.month,fileTIME.day,fileTIME.hour, fileTIME.minute, fileTIME.second) self.fileNamme = '.\data\data_%s.txt'%File_timestamp print(self.fileNamme) self.x_range = 180.1 self.x_interval = 10.0 self.y_range_Upper = 210.0 self.y_range_Lower = -90.0 self.y_interval = 20.0 self.unit = 'kPa' # default value, will replaced by actual reading. self.getReadingCommand = r"UPPER_VAL?\r\n" # default pass and pac self.getResp_rex = r'^[-]?([0-9]{1,}[.]?[0-9]*)' self.lenth = 40 # 10s caculate the slowrate # QwtPlot property # Initialize 坐标轴 self.setCanvasBackground(Qt.white) #Qt.white self.alignScales() grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) self.setAxisScale(QwtPlot.xBottom, 0.0,self.x_range,self.x_interval) #self.setAxisAutoScale(QwtPlot.yLeft,True) #self.setAxisScale(QwtPlot.yLeft,99.99,100.0,0.0005) self.setAxisScale(QwtPlot.yLeft,self.y_range_Lower,self.y_range_Upper,self.y_interval) self.setAxisLabelRotation(QwtPlot.xBottom,-45.0) self.x = np.arange(0.0, self.x_range + 1, 0.25)#0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms #self.z = np.zeros(len(self.x), np.float) list = [] for i in range(len(self.x)): list.append(0.0) self.z = np.array(list) rlist = [] for i in range(self.lenth): # 10s rlist.append(0.0) self.RateList = np.array(rlist) self.setTitle("UUT Reading Monitor - OutPort(%s)\r\n"%(self.unit)) self.insertLegend(QwtLegend(), QwtPlot.RightLegend); self.curveL = QwtPlotCurve("UUT Reading") self.curveL.attach(self) pen = QPen(Qt.red) pen.setWidth(1.5) self.curveL.setPen(pen) # show peak line and point value fn = self.fontInfo().family() self.peakMarker = m = QwtPlotMarker() m.setLineStyle(QwtPlotMarker.HLine) m.setLabelAlignment(Qt.AlignLeft | Qt.AlignTop) m.setLinePen(QPen(Qt.blue, 1.5, Qt.DashDotLine)) text = QwtText('dfdfdfdf') text.setColor(Qt.red) text.setBackgroundBrush(QBrush(self.canvasBackground())) text.setFont(QFont(fn, 12, QFont.Bold)) m.setLabel(text) # MarkPoint symbol m.setSymbol(QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.blue), QPen(Qt.green), QSize(7,7))) m.attach(self) # text marker self.txtMarker = m = QwtPlotMarker() m.setValue(self.x_range/2, self.y_range_Upper - self.y_interval/2) # show position m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) text = QwtText('initial') text.setFont(QFont(fn, 20, QFont.Bold)) text.setColor(Qt.white) text.setBackgroundBrush(QBrush(Qt.black)) text.setBorderPen(QPen(Qt.red, 2)) m.setLabel(text) m.attach(self) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading(%s)"%(self.unit)) self.replot() #self.startTimer(250)#ms# FOR GET READING self.starttime = time.clock();#unit: s self.idx = 0 self.readfmt = "%f" self.Saveinfo("Starting...")
def __init__(self, *args): QwtPlot.__init__(self, *args) self.Dev_COM = None self.uut_dev = None print(args) if args: self.Dev_COM = args[0] if self.Dev_COM: # Initialize Decice COM, self.uut_dev = device.SerialDevice(False, False, port=self.Dev_COM, baudrate=9600) else: # Initial LAN device #UUT PORT(NOTE: PC need to config the same ip section) self.uut_Client_ip = '169.254.1.3' self.uut_lan_port = 3490 # self.uut_buf_size = 1024 try: self.uut_dev = socket.socket(socket.AF_INET, socket.SOCK_STREAM) Addr = (self.uut_Client_ip, self.uut_lan_port) self.uut_dev.connect(Addr) print('Connectin created!') except Exception as e: # raise Exception(e) #print(self.sendcmd('SYST:REM\r\n')) print(self.sendcmd('*CLS\r\n')) fileTIME = datetime.datetime.now() File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % ( fileTIME.year, fileTIME.month, fileTIME.day, fileTIME.hour, fileTIME.minute, fileTIME.second) self.fileNamme = r'./data/data_%s.txt' % (File_timestamp) print(self.fileNamme) # 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,99.99,100.0,0.0005) self.x = np.arange( 0.0, 300, 0.5 ) #0.5 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms print(self.x) #self.z = np.zeros(len(self.x), np.float) list = [] for i in range(len(self.x)): list.append(0) self.z = np.array(list) self.setTitle("UUT Reading Monitor - (mA)") 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(mA)") self.replot() self.startTimer(500) # ms # FOR GET READING self.starttime = time.clock() #unit: s self.idx = 0 self.readfmt = "%f" self.Saveinfo("Starting...")