class TaurusTimeScaleDraw(FancyScaleDraw): def __init__(self, *args): FancyScaleDraw.__init__(self, *args) def setDatetimeLabelFormat(self, format): self._datetimeLabelFormat = format def datetimeLabelFormat(self): return self._datetimeLabelFormat def label(self, val): if str(self._labelFormat) == "": return Qwt5.QwtText() # From val to a string with time t = datetime.fromtimestamp(val) try: #If the scaleDiv was created by a DateTimeScaleEngine it has a _datetimeLabelFormat s = t.strftime(self._datetimeLabelFormat) except AttributeError, e: print "Warning: cannot get the datetime label format (Are you using a DateTimeScaleEngine?)" s = t.isoformat(' ') return Qwt5.QwtText(s)
def addPlotMarker(self, xPosition, label, samplecounter): ''' Create and add trigger event marker @param xPosition: horizontal screen position @param label: label string @param samplecounter: total sample position ''' margin = float(len(self.traces) + 1) / 10.0 / 3.0 # 2.5% bottom margin sym = Qwt.QwtSymbol() sym.setStyle(Qwt.QwtSymbol.VLine) sym.setSize(20) mX = Qwt.QwtPlotMarker() mX.setLabel(Qwt.QwtText(label)) mX.setLabelAlignment(Qt.Qt.AlignHCenter | Qt.Qt.AlignBottom) mX.setLineStyle(Qwt.QwtPlotMarker.NoLine) mX.setXValue(xPosition) mX.setYValue(-1.0 + margin) mX.setSymbol(sym) mX.sampleCounter = samplecounter mX.attach(self) self.plot_markers.append(mX)
def trackerText(self, point): x = self.plot.canvasMap(Qwt5.QwtPlot.xBottom).invTransform(point.x()) s = getTimestampFromDouble(x) for axis in [Qwt5.QwtPlot.yLeft, Qwt5.QwtPlot.yRight]: y = self.plot.canvasMap(axis).invTransform(point.y()) digits = int(("%.*e" % (1, y)).split('e')[1]) if digits > 4: astr = ' | %s' % pstr(y) elif digits > -1: astr = ' | %s' % pstr(y, 3) elif digits > -4: tmp = ' | %%1.%df' % (abs(digits) + 4) astr = tmp % y else: astr = ' | %.*e' % (3, y) s += astr s = s.replace('|', '\n') txt = Qwt5.QwtText(s) txt.setBackgroundBrush(self.backgroundBrush) return txt
def initialize(self): # attach a horizontal marker at y = 0 self.clear() self.curves = {} # set Markers marker = Qwt.QwtPlotMarker() marker.attach(self) marker.setValue(0.0, 25.0) marker.setLineStyle(Qwt.QwtPlotMarker.HLine) marker.setLabelAlignment(Qt.Qt.AlignLeft | Qt.Qt.AlignTop) marker.setLabel(Qwt.QwtText('NDVI = 0')) # self.pointMarker = Qwt.QwtPlotMarker() self.pointMarker.attach(self) # set Legend legend = Qwt.QwtLegend() legend.setItemMode(Qwt.QwtLegend.CheckableItem) self.insertLegend(legend, Qwt.QwtPlot.RightLegend) self.connect(self, Qt.SIGNAL('legendChecked(QwtPlotItem*, bool)'), self.showCurve)
def _initDataCursors(self): """ """ current_font = self.fontInfo().family() self.data_cursors = {} marker = qwt.QwtPlotMarker() marker.setValue(1, 200) text = qwt.QwtText('test') text.setFont(Qt.QFont(current_font, 12, Qt.QFont.Bold)) text.setColor(Qt.Qt.blue) text.setBackgroundBrush(Qt.QBrush(Qt.Qt.yellow)) text.setBackgroundPen(Qt.QPen(Qt.Qt.red, 2)) marker.setLabel(text) marker.setSymbol( qwt.QwtSymbol( qwt.QwtSymbol. Ellipse, # Marker Type (None, Ellipse, Rect, Diamond) Qt.QBrush( Qt.Qt.green ), # Fill Color (Use "Qt.QBrush()" if you want transparent) Qt.QPen( Qt.Qt.black, 6 ), # Edge Color & Edge Thickness (Use "Qt.QPen()" if you want transparent Qt.QSize(5, 5))) # Marker Size (Horizontal Size, Vertical Size) marker.setVisible(False) marker.attach(self.qwtPlot) data_cursor = PlotDataCursor(marker, qwt.QwtPlot.xBottom, qwt.QwtPlot.yLeft, qwt.QwtPicker.PointSelection, qwt.QwtPlotPicker.NoRubberBand, qwt.QwtPicker.AlwaysOff, self.qwtPlot.canvas()) data_cursor.setEnabled(False) self.data_cursors['qwtPlot'] = data_cursor
def showMs(self): self.cur.execute("select name,peakindex,peakintensity,MW from catalog where id=%d"%self.id) temp=self.cur.fetchall() masstemp=np.frombuffer(temp[0][1],dtype=np.int) intensitytemp=np.frombuffer(temp[0][2],dtype=np.int) row = np.zeros(len(masstemp)) mass = coo_matrix( (intensitytemp,(row,masstemp)), shape=(1,temp[0][3]+50)).todense() self.massSeacher=mass.tolist() radio_MS=0.01*(np.max(self.massSeacher[0])-np.min(self.massSeacher[0])) peak_MS=[] for i in range(5,len(self.massSeacher[0])-5): if (self.massSeacher[0][i]==max(self.massSeacher[0][i-5:i+5]) and self.massSeacher[0][i]>=radio_MS): peak_intensity_MS=(i,self.massSeacher[0][i]) peak_MS.append(peak_intensity_MS) self.plot1.clear() # self.plot1.setTitle("MS of %s"%str(temp[0][0][:-2])) self.plot1.setAxisScale(self.plot1.yLeft,0,1.1*np.max(self.massSeacher[0])) color = QColor('black') curve2 = Qwt.QwtPlotCurve("test1") pen = QPen(color) pen.setWidth(1) curve2.setPen(pen) self.axis= np.arange(temp[0][3]+50)+1 curve2.setData(self.axis,self.massSeacher[0]) curve2.setStyle(Qwt.QwtPlotCurve.Sticks) curve2.attach(self.plot1) for i in range(len(peak_MS)): text_MS=Qwt.QwtText('%s'%(str(peak_MS[i][0]))) marker_MS = Qwt.QwtPlotMarker() marker_MS.setLabelAlignment(Qt.AlignCenter | Qt.AlignTop) marker_MS.setLabel(text_MS) marker_MS.setValue(peak_MS[i][0],peak_MS[i][1]) marker_MS.attach(self.plot1) self.plot1.replot() self.ShowMolFile()
def arrangeTraces(self): ''' Setup display traces according to EEG data block settings ''' # select the requested channel group self.channel_group = self.eeg.eeg_channels[self.channel_slice] self.channel_group_properties = self.eeg.channel_properties[ self.channel_slice] # remove old traces for pc in self.traces: pc.detach() self.traces = [] # insert new traces font = Qt.QFont("arial", 8) for pccount in xrange(self.channel_group.shape[0]): color = self.channel_group_properties[pccount].color title = Qwt.QwtText(self.channel_group_properties[pccount].name) title.setFont(font) title.setColor(color) title.setPaintAttribute(Qwt.QwtText.PaintUsingTextFont) pc = Qwt.QwtPlotCurve(title) pc.setPen(Qt.QPen(color, 0)) pc.setYAxis(Qwt.QwtPlot.yLeft) pc.setPaintAttribute(Qwt.QwtPlotCurve.PaintFiltered) pc.attach(self) self.traces.append(pc) # reduce the legend items margin for item in self.legend().legendItems(): item.setMargin(0) # update Y axis scale self.setAxisScale(Qwt.QwtPlot.yLeft, -1.0, len(self.traces), 1.0) # update sample buffer self.setTimebase(self.timebase)
def initialize_plots(self): # Create time series plot self.plot_ts = self.ui.plot_ts self.plot_ts.setCanvasBackground(Qt.white) font = QtGui.QFont("default", pointSize=10) label = Qwt.QwtText("Elevation (m)") label.setFont(font) self.plot_ts.setAxisTitle(0, label) label.setText("Time (s)") self.plot_ts.setAxisTitle(2, label) self.grid = Qwt.QwtPlotGrid() self.grid.attach(self.plot_ts) self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) self.curve_ts = Qwt.QwtPlotCurve('') self.curve_ts.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) self.pen = QPen(QColor('black')) self.pen.setWidth(1.5) self.curve_ts.setPen(self.pen) self.curve_ts.attach(self.plot_ts) # Create output spectrum plot self.plot_spec = self.ui.plot_spec self.plot_spec.setCanvasBackground(Qt.white) label.setText("Spectral density") self.plot_spec.setAxisTitle(0, label) label.setText("Frequency (Hz)") self.plot_spec.setAxisTitle(2, label) self.grid = Qwt.QwtPlotGrid() self.grid.attach(self.plot_spec) self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) self.curve_spec = Qwt.QwtPlotCurve('') self.curve_spec.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) self.pen = QPen(QColor('black')) self.pen.setWidth(1.5) self.curve_spec.setPen(self.pen) self.curve_spec.attach(self.plot_spec)
def ShowMolFile(self): self.plot3.clear() self.ID = self.row1 Molecular = {} db = sqlite3.connect(MOL_DBPath) cur = db.cursor() cur.execute("select * from catalog where id=%d" % self.ID) c = cur.fetchall() Molecular["MolName"] = c[0][1] Molecular["MolNum"] = c[0][2] Molecular["MolBondNum"] = c[0][3] Molecular["Mol"] = c[0][4].split() Molecular["MolXAxis"] = np.frombuffer(c[0][5], dtype=np.float) Molecular["MolYAxis"] = np.frombuffer(c[0][6], dtype=np.float) Molecular["MolStyle"] = np.frombuffer(c[0][7], dtype=np.int) Molecular["bondX"] = np.frombuffer(c[0][8], dtype=np.int) Molecular["bondY"] = np.frombuffer(c[0][9], dtype=np.int) Molecular["bondNum"] = np.frombuffer(c[0][10], dtype=np.int) self.Molecular = Molecular color = QColor('black') curve = Qwt.QwtPlotCurve() pen = QPen(color) pen.setWidth(1) curve.setPen(pen) curve.setStyle(Qwt.QwtPlotCurve.NoCurve) curve.setSymbol( Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, Qt.black, QPen(Qt.black), QSize(3, 3))) curve.attach(self.plot3) curve.setData(self.Molecular["MolXAxis"], self.Molecular["MolYAxis"]) tempstyl1 = [] tempstyl2 = [] tempstyl3 = [] tempstyl4 = [] for i in range(Molecular["MolBondNum"]): if Molecular["bondNum"][i] == 1 and Molecular["MolStyle"][ Molecular["bondX"][i] - 1] == 0 and Molecular["MolStyle"][Molecular["bondY"][i] - 1] == 0: tempstyl2.append(Molecular["bondX"][i]) tempstyl2.append(Molecular["bondY"][i]) for i in range(Molecular["MolBondNum"]): if Molecular["bondNum"][i] == 2 and Molecular["MolStyle"][ Molecular["bondX"][i] - 1] == 0 and Molecular["MolStyle"][Molecular["bondY"][i] - 1] == 0: if (Molecular["bondX"][i] in tempstyl2) and (Molecular["bondY"][i] in tempstyl2): tempstyl1.append(Molecular["bondX"][i]) tempstyl1.append(Molecular["bondY"][i]) for i in range(len(tempstyl2) / 2): if (tempstyl2[2 * i] in tempstyl1) and (tempstyl2[2 * i + 1] in tempstyl1): tempstyl3.append(tempstyl2[2 * i]) tempstyl3.append(tempstyl2[2 * i + 1]) for i in range(len(tempstyl1) / 2): if (tempstyl1[2 * i] in tempstyl3) and (tempstyl1[2 * i + 1] in tempstyl3): tempstyl4.append(tempstyl1[2 * i]) tempstyl4.append(tempstyl1[2 * i + 1]) tempstyl6 = [] for i in range(len(tempstyl3) / 2): if (tempstyl3[2 * i] in tempstyl4) and (tempstyl3[2 * i + 1] in tempstyl4): tempstyl6.append(tempstyl3[2 * i]) tempstyl6.append(tempstyl3[2 * i + 1]) tempstyl5 = [] # print tempstyl4 while True: if len(tempstyl6) == 0 or len(tempstyl4) == 0: break for i in range(len(tempstyl4) / 2): # print i if not (tempstyl4[2 * i] in tempstyl5): tempindex3 = tempstyl6.index(tempstyl4[2 * i]) tempindex4 = tempstyl6.index(tempstyl4[2 * i + 1]) temp1 = tempstyl4[2 * i] temp2 = tempstyl4[2 * i + 1] if tempindex3 % 2 == 0: temp3 = tempstyl6[tempindex3 + 1] tempindex3other = tempindex3 + 1 else: temp3 = tempstyl6[tempindex3 - 1] tempindex3other = tempindex3 - 1 if tempindex4 % 2 == 0: temp4 = tempstyl6[tempindex4 + 1] tempindex4other = tempindex4 + 1 else: temp4 = tempstyl6[tempindex4 - 1] tempindex4other = tempindex4 - 1 tempindex5 = tempstyl4.index(temp3) tempindex6 = tempstyl4.index(temp4) if tempindex5 % 2 == 0: temp5 = tempstyl4[tempindex5 + 1] else: temp5 = tempstyl4[tempindex5 - 1] if tempindex6 % 2 == 0: temp6 = tempstyl4[tempindex6 + 1] else: temp6 = tempstyl4[tempindex6 - 1] tempindex7 = tempstyl6.index(temp5) if tempindex7 % 2 == 0: temp7 = tempstyl6[tempindex7 + 1] tempindex7other = tempindex7 + 1 else: temp7 = tempstyl6[tempindex7 - 1] tempindex7other = tempindex7 - 1 if temp7 == temp6: if not ((temp1 in tempstyl5) and (temp2 in tempstyl5) and (temp3 in tempstyl5) and (temp4 in tempstyl5) and (temp5 in tempstyl5) and (temp6 in tempstyl5)): tempstyl5.append(temp1) tempstyl5.append(temp2) tempstyl5.append(temp4) tempstyl5.append(temp3) tempstyl5.append(temp6) tempstyl5.append(temp5) temp = [ tempindex3, tempindex3other, tempindex4, tempindex4other, tempindex7, tempindex7other ] temp.sort(reverse=True) del tempstyl6[temp[0]] del tempstyl6[temp[1]] del tempstyl6[temp[2]] del tempstyl6[temp[3]] del tempstyl6[temp[4]] del tempstyl6[temp[5]] for i in np.arange((len(tempstyl4) - 1) / 2, -1, -1): if not (tempstyl4[2 * i] in tempstyl6) or not ( tempstyl4[2 * i + 1] in tempstyl6): del tempstyl4[2 * i + 1] del tempstyl4[2 * i] for i in np.arange((len(tempstyl6) - 1) / 2, -1, -1): if not (tempstyl6[2 * i] in tempstyl4) or not ( tempstyl6[2 * i + 1] in tempstyl4): del tempstyl6[2 * i + 1] del tempstyl6[2 * i] for i in np.arange((len(tempstyl4) - 1) / 2, -1, -1): if not (tempstyl4[2 * i] in tempstyl6) or not ( tempstyl4[2 * i + 1] in tempstyl6): del tempstyl4[2 * i + 1] del tempstyl4[2 * i] for i in np.arange((len(tempstyl6) - 1) / 2, -1, -1): if not (tempstyl6[2 * i] in tempstyl4) or not ( tempstyl6[2 * i + 1] in tempstyl4): del tempstyl6[2 * i + 1] del tempstyl6[2 * i] break # tempstylCom=list(set(tempstyl1) & set(tempstyl2)) # styl=np.setdiff1d(tempstyl1,tempstylCom) for i in range(Molecular["MolBondNum"]): x1 = self.Molecular["MolXAxis"][self.Molecular["bondX"][i] - 1] x2 = self.Molecular["MolXAxis"][self.Molecular["bondY"][i] - 1] y1 = self.Molecular["MolYAxis"][self.Molecular["bondX"][i] - 1] y2 = self.Molecular["MolYAxis"][self.Molecular["bondY"][i] - 1] if (y2 - y1) == 0: Xdiff = 0 Ydiff = np.sqrt(0.003) else: h = (x2 - x1) / (y2 - y1) Xdiff = np.sqrt(0.003 / (h * h + 1)) Ydiff = Xdiff * h if (Molecular["bondNum"][i] == 2) and not (Molecular["bondX"][i] in tempstyl5): tempx1 = [] tempy1 = [] tempx2 = [] tempy2 = [] tempx1.append(x1 + Xdiff) tempx1.append(x2 + Xdiff) tempy1.append(y1 - Ydiff) tempy1.append(y2 - Ydiff) tempx2.append(x1 - Xdiff) tempx2.append(x2 - Xdiff) tempy2.append(y1 + Ydiff) tempy2.append(y2 + Ydiff) curve2 = Qwt.QwtPlotCurve() curve2.setStyle(Qwt.QwtPlotCurve.Lines) curve2.attach(self.plot3) curve2.setData(tempx1, tempy1) curve3 = Qwt.QwtPlotCurve() curve3.setStyle(Qwt.QwtPlotCurve.Lines) curve3.attach(self.plot3) curve3.setData(tempx2, tempy2) elif (Molecular["bondNum"][i] == 3): tempx = [] tempy = [] tempx.append(x1) tempx.append(x2) tempy.append(y1) tempy.append(y2) curve1 = Qwt.QwtPlotCurve() curve1.setStyle(Qwt.QwtPlotCurve.Lines) curve1.attach(self.plot3) curve1.setData(tempx, tempy) tempx1 = [] tempy1 = [] tempx2 = [] tempy2 = [] tempx1.append(x1 + Xdiff) tempx1.append(x2 + Xdiff) tempy1.append(y1 - Ydiff) tempy1.append(y2 - Ydiff) tempx2.append(x1 - Xdiff) tempx2.append(x2 - Xdiff) tempy2.append(y1 + Ydiff) tempy2.append(y2 + Ydiff) curve2 = Qwt.QwtPlotCurve() curve2.setStyle(Qwt.QwtPlotCurve.Lines) curve2.attach(self.plot3) curve2.setData(tempx1, tempy1) curve3 = Qwt.QwtPlotCurve() curve3.setStyle(Qwt.QwtPlotCurve.Lines) curve3.attach(self.plot3) curve3.setData(tempx2, tempy2) else: tempx = [] tempy = [] tempx.append(x1) tempx.append(x2) tempy.append(y1) tempy.append(y2) curve1 = Qwt.QwtPlotCurve() curve1.setStyle(Qwt.QwtPlotCurve.Lines) curve1.attach(self.plot3) curve1.setData(tempx, tempy) t = np.linspace(0, np.pi * 2, 100) diffx1 = np.sin(t) * 0.3 diffy1 = np.cos(t) * 0.3 for i in range(len(tempstyl5) / 6): x0 = 0 y0 = 0 diffx = [] diffy = [] x0 = Molecular["MolXAxis"][tempstyl5[ 6 * i] - 1] + Molecular["MolXAxis"][tempstyl5[6 * i + 1] - 1] x0 = x0 + Molecular["MolXAxis"][tempstyl5[6 * i + 2] - 1] + Molecular["MolXAxis"][ tempstyl5[6 * i + 3] - 1] x0 = x0 + Molecular["MolXAxis"][tempstyl5[6 * i + 4] - 1] + Molecular["MolXAxis"][ tempstyl5[6 * i + 5] - 1] x0 = x0 / 6 y0 = Molecular["MolYAxis"][tempstyl5[ 6 * i] - 1] + Molecular["MolYAxis"][tempstyl5[6 * i + 1] - 1] y0 = y0 + Molecular["MolYAxis"][tempstyl5[6 * i + 2] - 1] + Molecular["MolYAxis"][ tempstyl5[6 * i + 3] - 1] y0 = y0 + Molecular["MolYAxis"][tempstyl5[6 * i + 4] - 1] + Molecular["MolYAxis"][ tempstyl5[6 * i + 5] - 1] y0 = y0 / 6 for i in range(len(diffx1)): diffx.append(diffx1[i] + x0) diffy.append(diffy1[i] + y0) curve4 = Qwt.QwtPlotCurve() curve4.setStyle(Qwt.QwtPlotCurve.Lines) curve4.attach(self.plot3) curve4.setData(diffx, diffy) for i in range(Molecular["MolNum"]): if Molecular["MolStyle"][i] != 0: text = Qwt.QwtText('%s' % Molecular["Mol"][i]) # text=Qwt.QwtText('%s'%str(i+1)) text.setColor(Qt.blue) text.setFont(QFont("Sans", 12)) text.setBackgroundBrush(Qt.white) marker = Qwt.QwtPlotMarker() marker.setLabelAlignment(Qt.AlignCenter | Qt.AlignCenter) marker.setLabel(text) marker.setValue(self.Molecular["MolXAxis"][i], self.Molecular["MolYAxis"][i]) marker.attach(self.plot3) self.plot3.setAxisScale(self.plot3.xBottom, min((min(Molecular["MolXAxis"]) - 0.5), -4), max((max(Molecular["MolXAxis"]) + 0.5), 4)) self.plot3.setAxisScale(self.plot3.yLeft, min((min(Molecular["MolYAxis"]) - 0.5), -4), max((max(Molecular["MolYAxis"]) + 0.5), 4)) self.plot3.replot()
def label(self, value): return Qwt.QwtText(str(value))
def label(self, val): if str(self._labelFormat) == "": return Qwt5.QwtText() if self._labelFormat is None: return Qwt5.QwtScaleDraw.label(self, val) else: return Qwt5.QwtText(self._labelFormat % val)
def label(self, val): if val >= 0: s = "+%s" % str(timedelta(seconds=val)) else: s = "-%s" % str(timedelta(seconds=-val)) return Qwt5.QwtText(s)
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) try: HISTORY = 60 * PROCESSgrTIMELINE except (NameError): QtCore.QCoreApplication.setApplicationName("Psymon") QtCore.QCoreApplication.setOrganizationName("Psymon") self.settings = QtCore.QSettings() self.settings.beginGroup("Process_Details_Tab") Process_Details_Tab_Timeline = self.settings.value( "Timeline_min_width").toInt() self.settings.endGroup() Process_Details_Tab_Timeline try: if Process_Details_Tab_Timeline[1] == False: _Process_Details_Tab_Timeline = 10 else: _Process_Details_Tab_Timeline = Process_Details_Tab_Timeline[ 0] except (IndexError): _Process_Details_Tab_Timeline = 10 PROCESSgrTIMELINE = _Process_Details_Tab_Timeline HISTORY = 60 * PROCESSgrTIMELINE self.curves = {} self.data = {} self.timeData = 1.0 * arange(HISTORY - 1, -1, -1) self.detailStat = DetailStat() self.setAutoReplot(False) self.plotLayout().setAlignCanvasToScales(True) legend = Qwt.QwtLegend() legend.setItemMode(Qwt.QwtLegend.CheckableItem) self.insertLegend(legend, Qwt.QwtPlot.RightLegend) self.xBottom_title = Qwt.QwtText( QtGui.QApplication.translate("MainWindow", "Timeline ", None, QtGui.QApplication.UnicodeUTF8) + str(PROCESSgrTIMELINE) + QtGui.QApplication.translate("MainWindow", "min [h:m:s]", None, QtGui.QApplication.UnicodeUTF8)) self.setAxisTitle(Qwt.QwtPlot.xBottom, self.xBottom_title) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, TimeScaleDraw(self.detailStat.nowTime())) self.setAxisScale(Qwt.QwtPlot.xBottom, 0, HISTORY) self.setAxisLabelRotation(Qwt.QwtPlot.xBottom, -05.0) self.setAxisLabelAlignment(Qwt.QwtPlot.xBottom, Qt.Qt.AlignLeft | Qt.Qt.AlignBottom) self.yLeft = Qwt.QwtText( QtGui.QApplication.translate("MainWindow", "Usage [%]", None, QtGui.QApplication.UnicodeUTF8)) self.setAxisTitle(Qwt.QwtPlot.yLeft, self.yLeft) self.setAxisScale(Qwt.QwtPlot.yLeft, 0, 100) self.setMinimumHeight(130) background = Background() background.attach(self) curve = DetailCurve('Memory') curve.setColor("#23A1FA") curve.attach(self) self.curves['Memory'] = curve self.data['Memory'] = zeros(HISTORY, Float) curve = DetailCurve('Cpu') curve.setColor(Qt.Qt.red) curve.setZ(curve.z() - 1.0) curve.attach(self) self.curves['Cpu'] = curve self.data['Cpu'] = zeros(HISTORY, Float) self.showCurve(self.curves['Memory'], True) self.showCurve(self.curves['Cpu'], True) self.startTimer(1000) self.connect(self, Qt.SIGNAL('legendChecked(QwtPlotItem*, bool)'), self.showCurve) self.replot()
def pickPlotPoint(self, pos, scope=20, showMarker=True, targetCurveNames=None, xlabels=None): '''Finds the pyxel-wise closest data point to the given position. The valid search space is constrained by the scope and targetCurveNames parameters. :param pos: (Qt.QPoint or Qt.QPolygon) the position around which to look for a data point. The position should be passed as a Qt.QPoint (if a Qt.QPolygon is given, the first point of the polygon is used). The position is expected in pixel units, with (0,0) being the top-left corner of the plot canvas. :param scope: (int) defines the area around the given position to be considered when searching for data points. A data point is considered within scope if its manhattan distance to position (in pixels) is less than the value of the scope parameter. (default=20) :param showMarker: (bool) If True, a marker will be put on the picked data point. (default=True) :param targetCurveNames: (sequence<str>) the names of the curves to be searched. If None passed, all curves will be searched :return: (tuple<Qt.QPointF,str,int> or tuple<None,None,None>) if a point was picked within the scope, it returns a tuple containing the picked point (as a Qt.QPointF), the curve name and the index of the picked point in the curve data. If no point was found within the scope, it returns None,None,None ''' print "pickPlotPoint(...)" if isinstance(pos, Qt.QPolygon): pos = pos.first() scopeRect = Qt.QRect(0, 0, scope, scope) scopeRect.moveCenter(pos) mindist = scope picked = None pickedCurveName = None pickedIndex = None self.curves_lock.acquire() try: if targetCurveNames is None: targetCurveNames = self.curves.keys() #print '%d targetCurveNames'%len(targetCurveNames) for name in targetCurveNames: curve = self.curves.get(name, None) if curve is None: #print("Curve '%s' not found"%name) continue if not curve.isVisible(): #print("Curve '%s' not visible"%name) continue data = curve.data() #print("Curve '%s' has %d points"%(name,data.size())) for i in xrange(data.size()): point = Qt.QPoint(self.transform(curve.xAxis(), data.x(i)), self.transform(curve.yAxis(), data.y(i))) if scopeRect.contains(point): #print( 'Comparing %s,%s vs %s'%(pos,scopeRect,point)) dist = (pos - point).manhattanLength() if dist < mindist: mindist = dist picked = Qt.QPointF(data.x(i), data.y(i)) pickedCurveName = name pickedIndex = i pickedAxes = curve.xAxis(), curve.yAxis() found = True #if picked: print("Curve '%s' contains %s"%(name,pos)) finally: self.curves_lock.release() if picked is None: print 'pickPlotPoint(%s)> No matching point found for any curve' % pos return xlabels = xlabels or [] print("pickPlotPoint(x=%s,y=%s,xlabels=[%s])" % (picked.x(), picked.y(), len(xlabels))) if showMarker and picked is not None: print 'showing pickedMarker' self._pickedMarker.detach() self._pickedMarker.setValue(picked) self._pickedMarker.setAxis(*pickedAxes) self._pickedMarker.attach(self) self._pickedCurveName = pickedCurveName self._pickedMarker.pickedIndex = pickedIndex self.replot() label = self._pickedMarker.label() try: xi, xl = ([(x[0], x[1]) for x in (xlabels or []) if x[0] <= picked.x()] or [[-1, None]])[-1] c = self.curves[pickedCurveName] #xc = [self.transform(c.xAxis(),x) for x in c.data().xData()] xc = [x for x in c.data().xData()] xx = len([x for x in xc if x >= xi and x <= picked.x()]) #print [x[0] for x in xlabels] #print 'picked point: %s'%picked.x() #print 'last label %s at %s'%(xl,xi) #print 'data point are %s'%(xc) #print 'data points between pick and label: %s'%xx index = xx tag = '%s-%02d' % (xl, index) if xl and '/ip' in pickedCurveName.lower(): try: tag = PyTango.AttributeProxy( tag.replace('-', '/VC/IP-') + '/Controller').read().value except: import traceback print traceback.format_exc() except: import traceback print traceback.format_exc() index, xl = (-1, None) tag = '' if xl: infotxt = "'%s'[%i]:\n\t (%s,%.2e)" % ( pickedCurveName, pickedIndex, tag, picked.y()) elif self.getXIsTime(): infotxt = "'%s'[%i]:\n\t (x=%s,%.3g)" % ( pickedCurveName, pickedIndex, datetime.fromtimestamp( picked.x()).ctime(), picked.y()) else: infotxt = "'%s'[%i]:\n\t (x=%.3g, y=%.3g)" % ( pickedCurveName, pickedIndex, picked.x(), picked.y()) label.setText(infotxt) print '\t%s' % infotxt fits = label.textSize().width() < self.size().width() if fits: label.setText(infotxt) self._pickedMarker.setLabel(Qwt5.QwtText(label)) self._pickedMarker.alignLabel() self.replot() else: popup = Qt.QWidget(self, Qt.Qt.Popup) popup.setLayout(Qt.QVBoxLayout()) popup.layout().addWidget( Qt.QLabel(infotxt) ) #@todo: make the widget background semitransparent green! popup.setWindowOpacity(self._pickedMarker.labelOpacity) popup.show() popup.move(self.pos().x() - popup.size().width(), self.pos().y()) popup.move(self.pos()) Qt.QTimer.singleShot(5000, popup.hide) return picked, pickedCurveName, pickedIndex
def label(self, v): s = time.strftime("%H:%M:%S", time.localtime(v)) s = QString(s) return Qwt.QwtText(s)
def label(self, value): nowTime = self.baseTime.addSecs(int(value)) return Qwt.QwtText(nowTime.toString())
def __init__(self, *args, **keys): ModuleBase.__init__(self, usethread=True, name="Display", **keys) # use transmit / receive thread Qwt.QwtPlot.__init__(self, *args) self.setMinimumSize(Qt.QSize(400, 200)) self.setObjectName("Display") # XML parameter version # 1: initial version # 2: scale and group size added # 3: baseline correction flag added # 4: timebase values changed from per division to screen (factor 10) # Type of timebase, scale and groupsize changed from string to float # 5: separate scale values for EEG and AUX channels self.xmlVersion = 5 #self.setTitle('ActiChamp'); self.setCanvasBackground(Qt.Qt.white) # create online configuration pane self.online_cfg = _OnlineCfgPane() self.connect(self.online_cfg.comboBoxTime, Qt.SIGNAL("activated(QString)"), self.timebaseChanged) self.connect(self.online_cfg.comboBoxScale, Qt.SIGNAL("currentIndexChanged(QString)"), self.scaleChanged) self.connect(self.online_cfg.comboBoxChannels, Qt.SIGNAL("currentIndexChanged(int)"), self.channelsChanged) self.connect(self.online_cfg.pushButton_Now, Qt.SIGNAL("clicked()"), self.baselineNowClicked) self.connect(self.online_cfg.checkBoxBaseline, Qt.SIGNAL("stateChanged()"), self.baselineNowClicked) # legend legend = _ScopeLegend() legend.setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Sunken) legend.setItemMode(Qwt.QwtLegend.ClickableItem) self.insertLegend(legend, Qwt.QwtPlot.LeftLegend) self.connect(self, Qt.SIGNAL("legendClicked(QwtPlotItem*)"), self.channelItemClicked) # grid self.grid = Qwt.QwtPlotGrid() self.grid.enableY(False) self.grid.enableX(True) self.grid.enableXMin(True) self.grid.setMajPen(Qt.QPen(Qt.Qt.gray, 0, Qt.Qt.SolidLine)) self.grid.setMinPen(Qt.QPen(Qt.Qt.gray, 0, Qt.Qt.DashLine)) self.grid.attach(self) # X axes font = Qt.QFont("arial", 9) title = Qwt.QwtText('Time [s]') title.setFont(font) self.setAxisTitle(Qwt.QwtPlot.xBottom, title) self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 5) self.setAxisMaxMinor(Qwt.QwtPlot.xBottom, 10) self.setAxisFont(Qwt.QwtPlot.xBottom, font) self.TimeScale = _TimeScaleDraw() self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, self.TimeScale) # Y axis self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Amplitude') self.setAxisMaxMajor(Qwt.QwtPlot.yLeft, 0) self.setAxisMaxMinor(Qwt.QwtPlot.yLeft, 0) self.enableAxis(Qwt.QwtPlot.yLeft, False) self.plotscale = Qwt.QwtPlotScaleItem(Qwt.QwtScaleDraw.RightScale) self.plotscale.setBorderDistance(5) self.plotscale.attach(self) # reset trace buffer self.traces = [] # reset marker buffer self.plot_markers = [] # list of QwtPlotMarker() self.input_markers = [] # list of EEG markers # EEG data block backup self.last_eeg = None self.last_slice = None # default settings self.setScale(self.online_cfg.get_scale()) # µV / Division self.timebase = self.online_cfg.get_timebase() # s / Screen self.xsize = 1500 self.binning = 300 self.binningoffset = 0 self.channel_slice = slice(0, 0, 1) # channel group selection self.baseline_request = False self.selectedChannel = None # set default display self.eeg = EEG_DataBlock() self.process_update(self.eeg) # timing test self.ttime = -1.0 self.tcount = 10.0 # start self.timerEvent() to update display asynchronously self.startTimer(30) self.update_display = False self.dataavailable = False
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))
def label(self, value): mbscale = str(value) return Qwt.QwtText(mbscale)
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) self.curves = {} self.data = {} self.timeData = 1.0 * arange(HISTORY - 1, -1, -1) self.networkStat = NetworkStat() self.setAutoReplot(False) self.plotLayout().setAlignCanvasToScales(True) legend = Qwt.QwtLegend() legend.setItemMode(Qwt.QwtLegend.CheckableItem) self.insertLegend(legend, Qwt.QwtPlot.RightLegend) self.xBottom_title = Qwt.QwtText( QtGui.QApplication.translate("MainWindow", "Timeline 60sec [h:m:s]", None, QtGui.QApplication.UnicodeUTF8)) self.setAxisTitle(Qwt.QwtPlot.xBottom, self.xBottom_title) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, TimeScaleDraw(self.networkStat.nowTime())) self.setAxisScale(Qwt.QwtPlot.xBottom, 0, HISTORY) self.setAxisLabelRotation(Qwt.QwtPlot.xBottom, -05.0) self.setAxisLabelAlignment(Qwt.QwtPlot.xBottom, Qt.Qt.AlignLeft | Qt.Qt.AlignBottom) self.yLeft = Qwt.QwtText( QtGui.QApplication.translate("MainWindow", "Usage [KB]", None, QtGui.QApplication.UnicodeUTF8)) self.setAxisTitle(Qwt.QwtPlot.yLeft, self.yLeft) self.setAxisScaleDraw(Qwt.QwtPlot.yLeft, NetScaleDraw(self.networkStat.mbscale())) self.setMinimumHeight(140) Qwt.QwtPlot.setAxisAutoScale(self, Qwt.QwtPlot.yLeft) background = Background() background.attach(self) curve = NetworkCurve('Net In') curve.setColor(Qt.Qt.green) curve.attach(self) self.curves['Net In'] = curve self.data['Net In'] = zeros(HISTORY, Float) curve = NetworkCurve('Net Out') curve.setColor(Qt.Qt.blue) curve.setZ(curve.z() - 1.0) curve.attach(self) self.curves['Net Out'] = curve self.data['Net Out'] = zeros(HISTORY, Float) self.showCurve(self.curves['Net In'], True) self.showCurve(self.curves['Net Out'], True) self.startTimer(1000) self.connect(self, Qt.SIGNAL('legendChecked(QwtPlotItem*, bool)'), self.showCurve) self.grid = Qwt.QwtPlotGrid() self.grid.enableX(False) self.grid.attach(self) global netdata, new_paint netdata = [0.0, 0.0] new_paint = True
def __init__(self, parent, logger): Qwt.QwtPlot.__init__(self) # store the logger instance self.logger = logger # we do not need caching self.canvas().setPaintAttribute(Qwt.QwtPlotCanvas.PaintCached, False) self.canvas().setPaintAttribute(Qwt.QwtPlotCanvas.PaintPacked, False) self.setAxisScale(Qwt.QwtPlot.yLeft, -140., 0.) xtitle = Qwt.QwtText('Frequency (Hz)') xtitle.setFont(QtGui.QFont(8)) self.setAxisTitle(Qwt.QwtPlot.xBottom, xtitle) # self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Frequency (Hz)') ytitle = Qwt.QwtText('PSD (dB A)') ytitle.setFont(QtGui.QFont(8)) self.setAxisTitle(Qwt.QwtPlot.yLeft, ytitle) # self.setAxisTitle(Qwt.QwtPlot.yLeft, 'PSD (dB)') # attach a grid grid = Qwt.QwtPlotGrid() grid.enableXMin(True) grid.setMajPen(Qt.QPen(Qt.QPen(Qt.Qt.gray))) grid.setMinPen(Qt.QPen(Qt.QPen(Qt.Qt.lightGray))) grid.attach(self) self.needfullreplot = False self.setAxisScale(Qwt.QwtPlot.xBottom, 63., 16000.) #self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, ) self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) #try: # s = Qwt.QwtLog10ScaleEngine() # s.autoScale(1,1.,1.) #except: # print "The loaded PyQwt library has buggy QwtScaleEngine (and friends) SIP declarations" # print "... use a log10 scale engine instead of a log2 scale engine" # self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) #else: # self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, log2scale.CustomScaleEngine()) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, FreqScaleDraw()) self.paint_time = 0. # picker used to display coordinates when clicking on the canvas self.picker = picker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.ActiveOnly, self.canvas()) # insert an additional plot item for the peak bar self.bar_peak = HistogramPeakBarItem() self.bar_peak.attach(self) self.peak = zeros((1,)) self.peak_int = 0 self.peak_decay = PEAK_DECAY_RATE self.histogram = HistogramItem() self.histogram.setColor(Qt.Qt.darkGreen) self.histogram.setBaseline(-200.) pos = [0.1, 1., 10.] self.histogram.setData(pos[:-1], pos[1:], pos[:-1]) self.histogram.attach(self) self.cached_canvas = self.canvas() # set the size policy to "Preferred" to allow the widget to be shrinked under the default size, which is quite big self.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) #need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.replot()
def label(self, value): if value >= 1e3: label = "%gk" % (value / 1e3) else: label = "%d" % (value) return Qwt.QwtText(label)
def trackerText(self, pos): pos2 = self.invTransform(pos) return Qwt.QwtText("%.2f s, %d Hz" % (pos2.x(), pos2.y()))
def __init__(self, qwt_plot, time_limit_index): super(PlotDisplay, self).__init__() self.curves = {} self.curve_data = {} # 字典存储曲线数据值,分为室温、水温、湿度三条曲线 self.time_data = [] # 存储时间坐标,单位:秒 self.time_limit = self.get_plot_time_limit( time_limit_index) # 存储用户选择时限的秒数 self.base_msec = 0 # 存储基准时间,即曲线起始时间 self.current_msec = QtCore.QDateTime.currentMSecsSinceEpoch() # 存储当前时间 self.selected_plot_node = {} # 选中节点,显示其曲线图 self.start_time = 0 # alias font = self.fontInfo().family() self.qwtPlot = qwt_plot text = Qwt.QwtText(u'水温[C\u00b0]') text.setColor(QtCore.Qt.blue) text.setFont(QtGui.QFont(font, 12, QtGui.QFont.Bold)) self.qwtPlot.setTitle(text) # axes self.qwtPlot.enableAxis(Qwt.QwtPlot.yRight) text = Qwt.QwtText(u'温度[C\u00b0]') text.setColor(QtCore.Qt.red) text.setFont(QtGui.QFont(font, 12, QtGui.QFont.Bold)) self.qwtPlot.setAxisTitle(Qwt.QwtPlot.yLeft, text) text = Qwt.QwtText(u'湿度 [\u00b0]') text.setColor(QtCore.Qt.darkGreen) text.setFont(QtGui.QFont(font, 12, QtGui.QFont.Bold)) self.qwtPlot.setAxisTitle(Qwt.QwtPlot.yRight, text) self.qwtPlot.setAxisScale(Qwt.QwtPlot.yLeft, 0, 100) self.qwtPlot.setAxisScale(Qwt.QwtPlot.yRight, 0, 100) self.qwtPlot.setCanvasBackground(QtCore.Qt.white) #self.qwtPlot.setAxisTitle(Qwt.QwtPlot.xBottom, u'日期时间') #self.qwtPlot.setAxisScale(Qwt.QwtPlot.xBottom, 0, 60) date_time = QtCore.QDateTime.currentDateTime() self.qwtPlot.setAxisScaleDraw(Qwt.QwtPlot.xBottom, TimeScaleDraw(date_time)) self.qwtPlot.setAxisLabelRotation(Qwt.QwtPlot.xBottom, -60.0) self.qwtPlot.setAxisLabelAlignment( Qwt.QwtPlot.xBottom, QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom) self.first_update_flag = True grid = Qwt.QwtPlotGrid() grid.attach(self.qwtPlot) grid.setPen(QtGui.QPen(QtCore.Qt.black, 0, QtCore.Qt.DotLine)) self.picker = PlotPickerByTime( Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.qwtPlot.canvas()) self.picker.setRubberBandPen(QtGui.QPen(QtCore.Qt.yellow)) self.picker.setTrackerPen(QtGui.QPen(QtCore.Qt.cyan)) #zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, # Qwt.QwtPlot.yLeft, # Qwt.QwtPicker.DragSelection, # Qwt.QwtPicker.AlwaysOff, # self.qwtPlot.canvas()) #zoomer.setRubberBandPen(QtGui.QPen(QtCore.Qt.darkGray)) curve = Qwt.QwtPlotCurve('Temperature Room') curve.setPen(QtGui.QPen(QtCore.Qt.red)) curve.attach(self.qwtPlot) self.curves[TROOM] = curve self.curve_data[TROOM] = [] curve = Qwt.QwtPlotCurve('Humidity') curve.setPen(QtGui.QPen(QtCore.Qt.darkGreen)) curve.attach(self.qwtPlot) self.curves[HUMIDITY] = curve self.curve_data[HUMIDITY] = [] curve = Qwt.QwtPlotCurve('Temperature Water') curve.setPen(QtGui.QPen(QtCore.Qt.blue)) curve.attach(self.qwtPlot) self.curves[TWATER] = curve self.curve_data[TWATER] = [] self.qwtPlot.setAutoReplot(False) self.qwtPlot.plotLayout().setAlignCanvasToScales(True) background = Background() background.attach(self.qwtPlot) self.connect(self.picker, QtCore.SIGNAL('moved(const QPoint &)'), self.moved) self.connect(self.picker, QtCore.SIGNAL('selected(const QPolygon &)'), self.selected)
def __init__(self, parent): DialogBase.__init__(self, "Adjust Contrast", ok=True, apply=True, cancel=True, user1=True, modal=False, parent=parent) self.parent = parent curDoc = self.parent.getCurrentDocument() # TESTING if curDoc.getURL == None: print "url is none" print curDoc.getURL() print curDoc.getURL().getFileName() # END TEST self.setWindowTitle("Adjust Contrast - " + str(curDoc.getURL().getFileName())) max = curDoc.getHistogram().shape[0] brightRange = curDoc.getBrightRange() self.setUser1ButtonText("Auto") w = QtGui.QWidget() layout = QtGui.QVBoxLayout() w.setLayout(layout) page = self.makeVBoxMainWidget() self.qhist1 = Qwt5.QwtPlot(Qwt5.QwtText("Entire Image")) layout.addWidget(self.qhist1) self.curve1 = Qwt5.QwtPlotCurve("Entire Image") self.curve1.attach(self.qhist1) self.curve1.setData( range(len(curDoc.getHistogram())), numpy.clip(curDoc.getHistogram(), 1, curDoc.getHistogram().max())) # set data and set zeros to ones because the logarithmic graphing does weird stuff with the zeros self.qhist1.setAxisTitle(Qwt5.QwtPlot.xBottom, "Pixel Value") self.qhist1.setAxisTitle(Qwt5.QwtPlot.yLeft, "Number of Pixels") self.qhist1.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) self.qhist1.replot() self.qhist2 = Qwt5.QwtPlot(Qwt5.QwtText("Selection")) layout.addWidget(self.qhist2) self.curve2 = Qwt5.QwtPlotCurve("Selection") self.curve2.attach(self.qhist2) tmpHist = curDoc.getHistogram() t2m = int(brightRange[0]) t2ma = int(brightRange[1] + 1) self.curve2.setData( range(t2m, t2ma), numpy.clip(tmpHist[t2m:t2ma], 1, tmpHist[t2m:t2ma].max())) self.qhist2.setAxisTitle(Qwt5.QwtPlot.xBottom, "Pixel Value") self.qhist2.setAxisTitle(Qwt5.QwtPlot.yLeft, "Number of Pixels") self.qhist2.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) self.qhist2.replot() # Blue marker historgram 1 self.blue1min = Qwt5.QwtPlotMarker() self.blue1min.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue1min.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue1min.setValue(t2m, 1) self.blue1min.attach(self.qhist1) self.blue1max = Qwt5.QwtPlotMarker() self.blue1max.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue1max.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue1max.setValue(t2ma, 1) self.blue1max.attach(self.qhist1) self.qhist1.replot() # Bluemarker histogram 2 self.blue2min = Qwt5.QwtPlotMarker() self.blue2min.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue2min.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue2min.setValue(t2m, 1) self.blue2min.attach(self.qhist2) self.blue2max = Qwt5.QwtPlotMarker() self.blue2max.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue2max.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue2max.setValue(t2ma, 1) self.blue2max.attach(self.qhist2) self.qhist2.replot() hlayout = QtGUI.QHBoxLayout() layout.addLayout(hlayout) minLabel = QtGui.QLabel("Min:") hlayout.addWidget(minLabel) self.minSlider = QtGui.QSlider() self.minSlider.setMinimum(0) self.minSlider.setMaximum(max) self.minSlider.setValue(brightRange[0]) self.minSlider.setOrientation(Qt.Horizontal) hlayout.addWidget(self.minSlider) layout.addWidget(w1) hlayout = QtGui.QHBoxLayout() layout.addLayout(hlayout) hlayout.addWidget(QtGui.QLabel("Max:")) self.maxSlider = QtGui.QSlider() self.maxSlider.setMinimum(0) self.maxSlider.setMaximum(max) self.maxSlider.setValue(brightRange[1]) self.maxSlider.setOrientation(Qt.Horizontal) hlayout.addWidget(self.maxSlider) hlayout = QtGui.QHBoxLayout() layout.addLayout(hlayout) self.allCheck = QtGui.QCheckBox("Changes Effect All Images") hlayout.addWidget(self.allCheck) # QLabel("Changes Effect All Images", bottomBox) hlayout = QtGui.QGridLayout() layout.addLayout(hlayout) hlayout.addWidget(QtGui.QLabel("Min:"), 0, 0) self.minSpinBox = QtGui.QSpinBox() self.minSpinBox.setMinimum(0) self.minSpinBox.setMaximum(max) self.minSpinBox.setValue(brightRange[0]) hlayout.addWidget(self.minSpinBox, 0, 1) hlayout.addWidget(QtGui.QLabel("Max:"), 1, 0) self.maxSpinBox = QSpinBox() self.maxSpinBox.setMinimum(0) self.maxSpinBox.setMaximum(max) self.maxSpinBox.setValue(brightRange[1]) self.minSlider.sliderMoved.connect(self.minSpinBox.setValue) self.maxSlider.sliderMoved.connect(self.maxSpinBox.setValue) self.minSpinBox.valueChanged.connect(self.minSlider.setValue) self.maxSpinBox.valueChanged.connect(self.maxSlider.setValue) self.minSpinBox.valueChanged.connect(self.slotChangeHist) self.maxSpinBox.valueChanged.connect(self.slotChangeHist) self.addWidget(w)
def __init__(self, parent, title, histData, rangePoints): QtGui.QWidget.__init__(self, parent) self.histData = histData min = 0 max = histData.shape[0] grid = QtGui.QGridLayout(self) self.graph = Qwt5.QwtPlot(Qwt5.QwtText(title)) grid.addWidget(self.graph, 0, 0) self.curve = Qwt5.QwtPlotCurve("Selection") self.curveFunc = Qwt5.QwtPlotCurve("SelectionFunc") self.curve.attach(self.graph) self.curveFunc.attach(self.graph) selectMin = int(rangePoints[0]) selectMax = int(rangePoints[1]) # if(selectMax < 1000): self.curve.setData( range(selectMin, selectMax), numpy.clip(histData[selectMin:selectMax + 1], 1, histData[selectMin:selectMax].max())) # else: # a=int(selectMax/1000) # sm=int(selectMin/a) # sx=int(selectMax/a) # self.curve.setData(range(sm, sx, a), self.histData[sm:sx]) # self.curveFunc.setData(range(selectMin,selectMax), numpy.array(range(0, selectMax-selectMin), numpy.float32)*255.0/(selectMax-selectMin)) self.graph.setAxisTitle(Qwt5.QwtPlot.xBottom, "Pixel Value") self.graph.setAxisTitle(Qwt5.QwtPlot.yLeft, "Number of Pixels") self.graph.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) # self.graph.enableAxis(Qwt5.QwtPlot.yRight) # self.graph.setAxisScale(Qwt5.QwtPlot.yRight, 0, 255) # Markers self.minMarker = Qwt5.QwtPlotMarker() self.minMarker.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.minMarker.setLinePen( QtGui.QPen(QtCore.Qt.blue, 1, QtCore.Qt.DashDotLine)) self.minMarker.setValue(selectMin, 1) self.minMarker.attach(self.graph) self.maxMarker = Qwt5.QwtPlotMarker() self.maxMarker.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.maxMarker.setLinePen( QtGui.QPen(QtCore.Qt.blue, 1, QtCore.Qt.DashDotLine)) self.maxMarker.setValue(selectMax, 1) self.maxMarker.attach(self.graph) # Slider # XXX: Sliders shouldn't be so exact so could have a larger range than int. self.graph.replot() minLayout = QtGui.QHBoxLayout() grid.addLayout(minLayout, 1, 0) minLabel = QtGui.QLabel("Min:") minLayout.addWidget(minLabel) self.minSlider = QtGui.QSlider(QtCore.Qt.Horizontal) self.minSlider.setRange(0, max) self.minSlider.setValue(selectMin) minLayout.addWidget(self.minSlider) maxLayout = QtGui.QHBoxLayout() grid.addLayout(maxLayout, 2, 0) maxLabel = QtGui.QLabel("Max:") maxLayout.addWidget(maxLabel) self.maxSlider = QtGui.QSlider(QtCore.Qt.Horizontal) self.maxSlider.setRange(0, max) self.maxSlider.setValue(selectMax) maxLayout.addWidget(self.maxSlider) # Spin boxes spinLayout = QtGui.QHBoxLayout() grid.addLayout(spinLayout, 3, 0) spinMinLabel = QtGui.QLabel("Min:") spinLayout.addWidget(spinMinLabel) self.minSpinBox = QtGui.QSpinBox() self.minSpinBox.setMinimum(0) self.minSpinBox.setMaximum(max) self.minSpinBox.setValue(selectMin) spinLayout.addWidget(self.minSpinBox) spinLayout = QtGui.QHBoxLayout() spinMaxLabel = QtGui.QLabel("Max:") grid.addLayout(spinLayout, 4, 0) spinLayout.addWidget(spinMaxLabel) self.maxSpinBox = QtGui.QSpinBox() self.maxSpinBox.setMinimum(0) self.maxSpinBox.setMaximum(max) self.maxSpinBox.setValue(selectMax) spinLayout.addWidget(self.maxSpinBox) # Connect slider and spinbox together self.minSlider.sliderMoved.connect(self.minSpinBox.setValue) self.maxSlider.sliderMoved.connect(self.maxSpinBox.setValue) self.minSpinBox.valueChanged.connect(self.minSlider.setValue) self.maxSpinBox.valueChanged.connect(self.maxSlider.setValue) # Connect spinbox with histogram self.minSpinBox.valueChanged.connect(self.slotChangeHist) self.maxSpinBox.valueChanged.connect(self.slotChangeHist)
def label(self, value): ret = Qwt.QwtText() v = value s = "%.2f" % (v) ret.setText(s) return ret
def setTitleFontSize(self, fontsize): title = Qwt.QwtText(self.run.get_id()) titlefont = title.font() titlefont.setPointSize(fontsize) title.setFont(titlefont) self.setTitle(title)
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) self.curves = {} self.data = {} self.timeData = 1.0 * arange(HISTORY - 1, -1, -1) self.cpuStat = CpuStat() self.setAutoReplot(False) self.plotLayout().setAlignCanvasToScales(True) legend = Qwt.QwtLegend() legend.setItemMode(Qwt.QwtLegend.CheckableItem) self.insertLegend(legend, Qwt.QwtPlot.RightLegend) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, TimeScaleDraw(self.cpuStat.nowTime())) self.setAxisScale(Qwt.QwtPlot.xBottom, 0, HISTORY) self.setAxisLabelRotation(Qwt.QwtPlot.xBottom, -05.0) self.setAxisLabelAlignment(Qwt.QwtPlot.xBottom, Qt.Qt.AlignLeft | Qt.Qt.AlignBottom) self.yLeft = Qwt.QwtText( QtGui.QApplication.translate("MainWindow", "Usage [%]", None, QtGui.QApplication.UnicodeUTF8)) self.setAxisTitle(Qwt.QwtPlot.yLeft, self.yLeft) self.setAxisScale(Qwt.QwtPlot.yLeft, 0, 100) self.setMinimumHeight(130) background = Background() background.attach(self) pie = CpuPieMarker() pie.attach(self) curve = CpuCurve('System') curve.setColor(Qt.Qt.green) curve.attach(self) self.curves['System'] = curve self.data['System'] = zeros(HISTORY, Float) curve = CpuCurve('User') curve.setColor(Qt.Qt.blue) curve.setZ(curve.z() - 1.0) curve.attach(self) self.curves['User'] = curve self.data['User'] = zeros(HISTORY, Float) curve = CpuCurve('Total') curve.setColor(Qt.Qt.black) curve.setZ(curve.z() - 2.0) curve.attach(self) self.curves['Total'] = curve self.data['Total'] = zeros(HISTORY, Float) curve = CpuCurve('Idle') curve.setColor(Qt.Qt.darkCyan) curve.setZ(curve.z() - 3.0) curve.attach(self) self.curves['Idle'] = curve self.data['Idle'] = zeros(HISTORY, Float) self.showCurve(self.curves['System'], True) self.showCurve(self.curves['User'], True) self.showCurve(self.curves['Total'], False) self.showCurve(self.curves['Idle'], False) self.startTimer(1000) self.connect(self, Qt.SIGNAL('legendChecked(QwtPlotItem*, bool)'), self.showCurve) self.replot()
def label(self, val): if str(self._labelFormat) == "": return Qwt5.QwtText() l = getTimestampFromDouble(val) l = l.split()[0] + '\n' + l.split()[1] return Qwt5.QwtText(l)