def __initZooming(self): self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.ActiveOnly, self.gui.plot.canvas()) self.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.black)) self.zoomer.initMousePattern(0)
def _make_zoomer(self, plot): zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOn, plot.canvas()) zoomer.setRubberBandPen(QtGui.QPen(QtCore.Qt.white)) zoomer.setTrackerPen(QtGui.QPen(QtCore.Qt.cyan)) return zoomer
def initialize(self): self.colors = [ QtGui.QColor(255, 0, 0), QtGui.QColor(50, 50, 50), QtGui.QColor(255, 0, 255), QtGui.QColor(0, 200, 100), QtGui.QColor(0, 0, 255), QtGui.QColor(255, 0, 80), QtGui.QColor(100, 0, 80), QtGui.QColor(100, 0, 0) ] self.curves = [] self.ranges = [] self.setCanvasBackground(Qt.Qt.white) picker_on = Qwt.QwtPicker.AlwaysOn picker_on = Qwt.QwtPicker.AlwaysOff self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, picker_on, self.canvas()) self.zoomer.setRubberBandPen(QtGui.QPen(Qt.Qt.black)) self.zoomer.setTrackerPen(QtGui.QPen(Qt.Qt.black)) self.panner = Qwt.QwtPlotPanner(self.canvas()) self.panner.setMouseButton(Qt.Qt.MidButton)
def __initZooming(self): """Initialize zooming """ self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, self.plot.canvas()) self.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.black))
def __init__(self, blkname="pyqt_raster", label="", *args): gr.sync_block.__init__(self, blkname, [], []) Qwt.QwtPlot.__init__(self, *args) self.enabled = True # set up message port self.message_port_register_in(pmt.intern("pdus")) self.set_msg_handler(pmt.intern("pdus"), self.handler) # QwtPlot set up self.setMinimumWidth(100) self.setMinimumHeight(100) self._lock = threading.Lock() # set up label if desired if not label == "": ttl = Qwt.QwtText(label) ttl.setFont(Qt.QFont("Helvetica", 10)) self.setTitle(ttl) # wedge everything as close as possible self.plotLayout().setMargin(0) self.plotLayout().setCanvasMargin(0) self.plotLayout().setSpacing(0) # set up background etc self.setCanvasBackground(Qt.Qt.black) self.alignScales() # set up image raster dim = (100, 100) self.__data = PlotImage('Image', dim[0], dim[1]) self.__data.attach(self) self.__data.setData(numpy.random.normal(0, 1e-9, dim)) self.replot() # connect the plot callback signal QtCore.QObject.connect(self, QtCore.SIGNAL("updatePlot(int)"), self.do_plot) # set up zoomer 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.black)) # Set up menu actions actions = [ ("Start/Stop", self.toggle_enabled), ] self.actions = [] for a in actions: action = QtGui.QAction(a[0], self) action.triggered.connect(a[1]) self.actions.append(action)
def __init__(self, blkname="pyqt_plotter", label="", *args): gr.sync_block.__init__(self, blkname, [], []) Qwt.QwtPlot.__init__(self, *args) self.enabled = True self.setMinimumWidth(100) self.setMinimumHeight(100) # set up label if desired if not label == "": ttl = Qwt.QwtText(label) ttl.setFont(Qt.QFont("Helvetica", 10)) self.setTitle(ttl) # wedge everything as close as possible self.plotLayout().setMargin(0) self.plotLayout().setCanvasMargin(0) self.plotLayout().setSpacing(0) # set up background etc self.setCanvasBackground(Qt.Qt.black) self.alignScales() # curve storage self.curves = [] self.curve_data = [] # connect the plot callback signal QtCore.QObject.connect(self, QtCore.SIGNAL("updatePlot(int)"), self.do_plot) QtCore.QObject.connect(self, QtCore.SIGNAL("updatePlot(int)"), self.do_plot) # set up zoomer 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.black)) # Set up menu actions actions = [("Start/Stop", self.toggle_enabled), ("Toggle Grid", self.toggle_grid), ("Toggle Axes", self.toggle_axes), ("Clear Markers", self.clear_markers)] self.actions = [] for a in actions: action = QtGui.QAction(a[0], self) action.triggered.connect(a[1]) self.actions.append(action) # set up some other stuff ... self.grid = None self.toggle_axes() # self.toggle_grid() self.markers = []
def __init__(self, parent=None): Qwt.QwtPlot.__init__(self, parent) self.__spectrogram = Qwt.QwtPlotSpectrogram() self.zoomer = Qwt.QwtPlotZoomer(self.canvas()) self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect2, Qt.Qt.RightButton, Qt.Qt.ControlModifier) self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect3, Qt.Qt.RightButton) self.zoomer.setRubberBandPen(Qt.Qt.darkBlue) self.zoomer.setTrackerPen(Qt.Qt.darkBlue) xmin = -10 ymin = -10 xmax = 10 ymax = 10 x_a = [] y_a = [] intes = [] for x in np.linspace(xmin, xmax, 50): for y in np.linspace(ymin, ymax, 50): x_a.append(x) y_a.append(y) # I just used a random function from https://www.physicsforums.com/threads/cool-3-d-functions-for-graphing.140087/ to display # intes.append(x+y) # This is the actual function I used for testing. It is much simplier and you can tell where every point should be intes.append(max([-2*(round(math.e**(-(x*2)**2)) + round(math.e**(-(y*2)**2)))+ 2+2*math.cos((x**2+y**2)/4), 25*math.e**(-1*(x**2+y**2)*3)])) # # x_a = sorted(x_a, reverse= True) # y_a = sorted(y_a, reverse=True) intes = np.asarray(intes) rightAxis = self.axisWidget(Qwt.QwtPlot.yRight) rightAxis.setTitle("Intensity") rightAxis.setColorBarEnabled(True) rightAxis.setColorMap(self.__spectrogram.data().range(), self.__spectrogram.colorMap()) self.enableAxis(Qwt.QwtPlot.yRight) # LeftButton for the zooming # MidButton for the panning # RightButton: zoom out by 1 # Ctrl+RighButton: zoom out to full size # panner = Qwt.QwtPlotPanner(self.canvas()) panner.setAxisEnabled(Qwt.QwtPlot.yRight, False) panner.setMouseButton(Qt.Qt.MidButton) # Avoid jumping when labels with more/less digits # appear/disappear when scrolling vertically # fm = Qt.QFontMetrics(self.axisWidget(Qwt.QwtPlot.yLeft).font()) self.axisScaleDraw( Qwt.QwtPlot.yLeft).setMinimumExtent(fm.width("100.00"))
def __init__(self, parent=None): Qwt.QwtPlot.__init__(self, parent) self.__spectrogram = Qwt.QwtPlotSpectrogram() colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red) colorMap.addColorStop(0.1, Qt.Qt.cyan) colorMap.addColorStop(0.6, Qt.Qt.green) colorMap.addColorStop(0.95, Qt.Qt.yellow) self.__spectrogram.setColorMap(colorMap) self.__spectrogram.setData(SpectrogramData()) self.__spectrogram.attach(self) self.__spectrogram.setContourLevels( [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]) rightAxis = self.axisWidget(Qwt.QwtPlot.yRight) rightAxis.setTitle("Intensity") rightAxis.setColorBarEnabled(True) rightAxis.setColorMap(self.__spectrogram.data().range(), self.__spectrogram.colorMap()) self.setAxisScale(Qwt.QwtPlot.yRight, self.__spectrogram.data().range().minValue(), self.__spectrogram.data().range().maxValue()) self.enableAxis(Qwt.QwtPlot.yRight) self.plotLayout().setAlignCanvasToScales(True) self.replot() # LeftButton for the zooming # MidButton for the panning # RightButton: zoom out by 1 # Ctrl+RighButton: zoom out to full size zoomer = Qwt.QwtPlotZoomer(self.canvas()) zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect2, Qt.Qt.RightButton, Qt.Qt.ControlModifier) zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect3, Qt.Qt.RightButton) zoomer.setRubberBandPen(Qt.Qt.darkBlue) zoomer.setTrackerPen(Qt.Qt.darkBlue) panner = Qwt.QwtPlotPanner(self.canvas()) panner.setAxisEnabled(Qwt.QwtPlot.yRight, False) panner.setMouseButton(Qt.Qt.MidButton) # Avoid jumping when labels with more/less digits # appear/disappear when scrolling vertically fm = Qt.QFontMetrics(self.axisWidget(Qwt.QwtPlot.yLeft).font()) self.axisScaleDraw(Qwt.QwtPlot.yLeft).setMinimumExtent( fm.width("100.00"))
def main(args): app = Qt.QApplication(args) demo = make() zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, demo.canvas()) zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.green)) picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.NoSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, demo.canvas()) picker.setTrackerPen(Qt.QPen(Qt.Qt.red)) sys.exit(app.exec_())
def initZoom(self): """Add zooming capabilities on the QwtPlot """ 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.black)) # FIXME : deactivate unzoom on right click self.zoomer.setMousePattern([ Qwt.QwtEventPattern.MousePattern(Qt.Qt.MidButton, Qt.Qt.NoModifier), ]) self.zoomer.initMousePattern(0)
def __init__(self, grblock, *args): Qwt.QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.Qt.white) self.grblock = grblock # Initialize data self.t = np.arange(self.grblock.ntau) self.pdp = np.zeros(self.t.size) self.setTitle("Power Delay Profile") self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend) self.pdpcurve = Qwt.QwtPlotCurve("PDP") self.pdpcurve.attach(self) self.pdpcurve.setPen(Qt.QPen(Qt.Qt.red)) mY = Qwt.QwtPlotMarker() mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop) mY.setLineStyle(Qwt.QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)") scale = time_scale(self.grblock.t_symbol) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, scale) self.setAxisTitle(Qwt.QwtPlot.yLeft, "Power") self.setAxisScale(Qwt.QwtPlot.yLeft, -100, 0) # for linear scale #self.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) # zoomer 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)) # picker showing the coordinates at the mouse pointer self.picker = QwtPlotPicker(self.grblock.t_symbol, Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.canvas()) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan))
def PlotZooming(self, theplot): """Initialize zooming """ if not hasattr( theplot, 'zoomer'): # only attach the zoomer to the plot at the start theplot.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOff, theplot.canvas()) theplot.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.red)) theplot.zoomer.initMousePattern(2) theplot.setAxisAutoScale( Qwt.QwtPlot.yLeft) # make sure we are autoscaled theplot.setAxisAutoScale(Qwt.QwtPlot.xBottom) theplot.zoomer.setZoomBase() # make sure we reset the base to be save
def makeplot(self): '''set up plotting''' # make any contents fill the empty frame self.ui.axes.setLayout(QtGui.QGridLayout(self.ui.axes)) # Draw a plot in the frame. We do this, rather than defining the # QwtPlot object in Qt designer because loadUi then fails! plot = Qwt5.QwtPlot(self.ui.axes) self.ui.axes.layout().addWidget(plot) self.plot = plot self.cx = self.makecurve(X_colour) self.cy = self.makecurve(Y_colour) # set background to black plot.setCanvasBackground(QtCore.Qt.black) # Enable zooming plot.setStatusTip(self.Plot_tooltip) zoom = Qwt5.QwtPlotZoomer(plot.canvas()) zoom.setRubberBandPen(QtGui.QPen(QtCore.Qt.white)) zoom.setTrackerPen(QtGui.QPen(QtCore.Qt.white)) # This is a poorly documented trick to disable the use of the right # button for cancelling zoom, so we can use it for panning instead. The # first argument of setMousePattern() selects the zooming action, and is # one of the following with the given default assignment: # # Index Button Action # 0 Left Mouse Start and stop rubber band selection # 1 Right Mouse Restore to original unzoomed axes # 2 Middle Mouse Zoom out one level # 3 Shift Left ? # 4 Shift Right ? # 5 Shift Middle Zoom back in one level zoom.setMousePattern(1, QtCore.Qt.NoButton) self.zoom = zoom # Enable panning. We reconfigure the active mouse to use the right # button so that panning and zooming can coexist. pan = Qwt5.QwtPlotPanner(plot.canvas()) pan.setMouseButton(QtCore.Qt.RightButton) # Monitor mouse movements over the plot area so we can show the position # in coordinates. SpyMouse(plot.canvas()).MouseMove.connect(self.mouse_move)
def Seach(self): ms = self.ms nist = NISTSearch(NIST_DBPath) nist.top10_screen(self.ms) nist.corr() self.masscor = nist.corrs db = sqlite3.connect(NIST_DBPath) self.cur = db.cursor() for i in range(min(25, len(self.masscor))): self.cur.execute( "select name,Formula,MW from catalog where id=%d" % self.masscor[i][0]) temp = self.cur.fetchall() strsimilarity = '%.2f' % self.masscor[i][1] temp3 = temp[0][1][:-1] temp1 = temp[0][2] temp2 = temp[0][0][:-2] item = QTreeWidgetItem([ str(i + 1), str(strsimilarity), str(temp1), str(temp3), str(temp2) ]) self.library_list.addTopLevelItem(item) if len(ms) > 0: self.showMs(self.masscor[0][0]) zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOn, self.plot1.canvas()) zoomer.setRubberBandPen(QPen(Qt.black)) zoomer.setTrackerPen(QPen(Qt.blue)) self.plot1.zoomer = zoomer self.plot1.zoomer.setZoomBase()
def __init__(self, qapp, options): QtGui.QWidget.__init__(self, None) self.gui = Ui_MainWindow() self.gui.setupUi(self) self.connect(self.gui.action_save, Qt.SIGNAL("activated()"), self.action_save_dialog) self.connect(self.gui.action_open, Qt.SIGNAL("activated()"), self.action_open_dialog) self.connect(self.gui.filterTypeComboBox, Qt.SIGNAL("currentIndexChanged(const QString&)"), self.changed_filter_type) self.connect(self.gui.filterDesignTypeComboBox, Qt.SIGNAL("currentIndexChanged(const QString&)"), self.changed_filter_design_type) self.connect(self.gui.designButton, Qt.SIGNAL("released()"), self.design) self.connect(self.gui.tabGroup, Qt.SIGNAL("currentChanged(int)"), self.tab_changed) self.connect(self.gui.nfftEdit, Qt.SIGNAL("textEdited(QString)"), self.nfft_edit_changed) self.gui.designButton.setShortcut(QtCore.Qt.Key_Return) self.taps = [] self.fftdB = [] self.fftDeg = [] self.groupDelay = [] self.nfftpts = int(10000) self.gui.nfftEdit.setText(Qt.QString("%1").arg(self.nfftpts)) self.firFilters = ("Low Pass", "Band Pass", "Complex Band Pass", "Band Notch", "High Pass", "Root Raised Cosine", "Gaussian") self.optFilters = ("Low Pass", "Band Pass", "Complex Band Pass", "Band Notch", "High Pass") self.set_windowed() # Initialize to LPF self.gui.filterTypeWidget.setCurrentWidget(self.gui.firlpfPage) # Set Axis labels self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.xBottom, "Frequency (Hz)") self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.yLeft, "Magnitude (dB)") self.gui.timePlot.setAxisTitle(self.gui.timePlot.xBottom, "Tap number") self.gui.timePlot.setAxisTitle(self.gui.timePlot.yLeft, "Amplitude") self.gui.phasePlot.setAxisTitle(self.gui.phasePlot.xBottom, "Frequency (Hz)") self.gui.phasePlot.setAxisTitle(self.gui.phasePlot.yLeft, "Phase (Radians)") self.gui.groupPlot.setAxisTitle(self.gui.groupPlot.xBottom, "Frequency (Hz)") self.gui.groupPlot.setAxisTitle(self.gui.groupPlot.yLeft, "Delay (sec)") # Set up plot curves self.rcurve = Qwt.QwtPlotCurve("Real") self.rcurve.attach(self.gui.timePlot) self.icurve = Qwt.QwtPlotCurve("Imag") self.icurve.attach(self.gui.timePlot) self.freqcurve = Qwt.QwtPlotCurve("PSD") self.freqcurve.attach(self.gui.freqPlot) self.phasecurve = Qwt.QwtPlotCurve("Phase") self.phasecurve.attach(self.gui.phasePlot) self.groupcurve = Qwt.QwtPlotCurve("Group Delay") self.groupcurve.attach(self.gui.groupPlot) # Create zoom functionality for the plots self.timeZoomer = Qwt.QwtPlotZoomer(self.gui.timePlot.xBottom, self.gui.timePlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.timePlot.canvas()) self.freqZoomer = Qwt.QwtPlotZoomer(self.gui.freqPlot.xBottom, self.gui.freqPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.freqPlot.canvas()) self.phaseZoomer = Qwt.QwtPlotZoomer(self.gui.phasePlot.xBottom, self.gui.phasePlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.phasePlot.canvas()) self.groupZoomer = Qwt.QwtPlotZoomer(self.gui.groupPlot.xBottom, self.gui.groupPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.groupPlot.canvas()) # Set up pen for colors and line width blue = QtGui.qRgb(0x00, 0x00, 0xFF) blueBrush = Qt.QBrush(Qt.QColor(blue)) red = QtGui.qRgb(0xFF, 0x00, 0x00) redBrush = Qt.QBrush(Qt.QColor(red)) self.freqcurve.setPen(Qt.QPen(blueBrush, 2)) self.rcurve.setPen(Qt.QPen(blueBrush, 2)) self.icurve.setPen(Qt.QPen(redBrush, 2)) self.phasecurve.setPen(Qt.QPen(blueBrush, 2)) self.groupcurve.setPen(Qt.QPen(blueBrush, 2)) # Set up validators for edit boxes self.intVal = Qt.QIntValidator(None) self.dblVal = Qt.QDoubleValidator(None) self.gui.nfftEdit.setValidator(self.intVal) self.gui.sampleRateEdit.setValidator(self.dblVal) self.gui.filterGainEdit.setValidator(self.dblVal) self.gui.endofLpfPassBandEdit.setValidator(self.dblVal) self.gui.startofLpfStopBandEdit.setValidator(self.dblVal) self.gui.lpfStopBandAttenEdit.setValidator(self.dblVal) self.gui.lpfPassBandRippleEdit.setValidator(self.dblVal) self.gui.startofBpfPassBandEdit.setValidator(self.dblVal) self.gui.endofBpfPassBandEdit.setValidator(self.dblVal) self.gui.bpfTransitionEdit.setValidator(self.dblVal) self.gui.bpfStopBandAttenEdit.setValidator(self.dblVal) self.gui.bpfPassBandRippleEdit.setValidator(self.dblVal) self.gui.startofBnfStopBandEdit.setValidator(self.dblVal) self.gui.endofBnfStopBandEdit.setValidator(self.dblVal) self.gui.bnfTransitionEdit.setValidator(self.dblVal) self.gui.bnfStopBandAttenEdit.setValidator(self.dblVal) self.gui.bnfPassBandRippleEdit.setValidator(self.dblVal) self.gui.endofHpfStopBandEdit.setValidator(self.dblVal) self.gui.startofHpfPassBandEdit.setValidator(self.dblVal) self.gui.hpfStopBandAttenEdit.setValidator(self.dblVal) self.gui.hpfPassBandRippleEdit.setValidator(self.dblVal) self.gui.rrcSymbolRateEdit.setValidator(self.dblVal) self.gui.rrcAlphaEdit.setValidator(self.dblVal) self.gui.rrcNumTapsEdit.setValidator(self.dblVal) self.gui.gausSymbolRateEdit.setValidator(self.dblVal) self.gui.gausBTEdit.setValidator(self.dblVal) self.gui.gausNumTapsEdit.setValidator(self.dblVal) self.gui.nTapsEdit.setText("0") self.filterWindows = { "Hamming Window": gr.firdes.WIN_HAMMING, "Hann Window": gr.firdes.WIN_HANN, "Blackman Window": gr.firdes.WIN_BLACKMAN, "Rectangular Window": gr.firdes.WIN_RECTANGULAR, "Kaiser Window": gr.firdes.WIN_KAISER, "Blackman-harris Window": gr.firdes.WIN_BLACKMAN_hARRIS } self.EQUIRIPPLE_FILT = 6 # const for equiripple filter window types self.show()
def __init__(self, grblock, *args): Qwt.QwtPlot.__init__(self, *args) self.grblock = grblock self.scatter = np.zeros((self.grblock.nt, self.grblock.ntau)) # set plot title self.setTitle('Scattering Function') # 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, 'Delay (s)') self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Doppler Spectrum (Hz)') # scale x-axis t_scale = time_scale(self.grblock.t_symbol) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, t_scale) # scale y-axis f_scale = freq_scale(self.grblock.prf, self.grblock.nt) self.setAxisScaleDraw(Qwt.QwtPlot.yLeft, f_scale) # create a QwtRasterData instance to store the numpy array # produced by the GNU Radio Python sink block self.scatter_data = ScatterData(self.scatter) # create a QwtPlotSpectrogram instance to plot the QwtRasterData self.plot_scatter = Qwt.QwtPlotSpectrogram() # create a greyscale colormap colorMap = Qwt.QwtLinearColorMap(Qt.Qt.black, Qt.Qt.white) self.plot_scatter.setColorMap(colorMap) # attach and pass the data self.plot_scatter.attach(self) self.plot_scatter.setData(self.scatter_data) # replot self.replot() # zoomer 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)) # picker showing the coordinates at the mouse pointer self.picker = QwtPlotPicker(self.grblock.t_symbol, self.grblock.nt, self.grblock.prf, Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn, self.canvas()) self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan))
def __init__(self, qapp, filename, options, parent=None): QtGui.QWidget.__init__(self, parent) self.gui = Ui_MainWindow() self.gui.setupUi(self) self.filename = None self.block_length = options.block_length self.start = options.start self.sample_rate = options.sample_rate self.psdfftsize = options.psd_size self.specfftsize = options.spec_size self.winfunc = scipy.blackman self.sizeof_data = 8 self.datatype = scipy.complex64 self.pen_width = 1 self.iq = list() self.time = list() # Set up basic plot attributes self.gui.timePlot.setAxisTitle(self.gui.timePlot.xBottom, "Time (sec)") self.gui.timePlot.setAxisTitle(self.gui.timePlot.yLeft, "Amplitude (V)") self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.xBottom, "Frequency (Hz)") self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.yLeft, "Magnitude (dB)") self.gui.specPlot.setAxisTitle(self.gui.specPlot.xBottom, "Frequency (Hz)") self.gui.specPlot.setAxisTitle(self.gui.specPlot.yLeft, "Time (sec)") # Set up FFT size combo box self.fftsizes = ["128", "256", "512", "1024", "2048", "4096", "8192", "16384", "32768"] self.gui.psdFFTComboBox.addItems(self.fftsizes) self.gui.specFFTComboBox.addItems(self.fftsizes) pos = self.gui.psdFFTComboBox.findText(Qt.QString("%1").arg(self.psdfftsize)) self.gui.psdFFTComboBox.setCurrentIndex(pos) pos = self.gui.specFFTComboBox.findText(Qt.QString("%1").arg(self.specfftsize)) self.gui.specFFTComboBox.setCurrentIndex(pos) self.connect(self.gui.psdFFTComboBox, Qt.SIGNAL("activated (const QString&)"), self.psdFFTComboBoxEdit) self.connect(self.gui.specFFTComboBox, Qt.SIGNAL("activated (const QString&)"), self.specFFTComboBoxEdit) # Set up color scheme box self.color_modes = {"Black on White" : self.color_black_on_white, "White on Black" : self.color_white_on_black, "Blue on Black" : self.color_blue_on_black, "Green on Black" : self.color_green_on_black} self.gui.colorComboBox.addItems(self.color_modes.keys()) pos = self.gui.colorComboBox.findText("Blue on Black") self.gui.colorComboBox.setCurrentIndex(pos) self.connect(self.gui.colorComboBox, Qt.SIGNAL("activated (const QString&)"), self.colorComboBoxEdit) # Set up line style combo box self.line_styles = {"None" : Qwt.QwtSymbol.NoSymbol, "Circle" : Qwt.QwtSymbol.Ellipse, "Diamond" : Qwt.QwtSymbol.Rect, "Triangle" : Qwt.QwtSymbol.Triangle} self.gui.lineStyleComboBox.addItems(self.line_styles.keys()) pos = self.gui.lineStyleComboBox.findText("None") self.gui.lineStyleComboBox.setCurrentIndex(pos) self.connect(self.gui.lineStyleComboBox, Qt.SIGNAL("activated (const QString&)"), self.lineStyleComboBoxEdit) # Create zoom functionality for the plots self.timeZoomer = Qwt.QwtPlotZoomer(self.gui.timePlot.xBottom, self.gui.timePlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.timePlot.canvas()) self.freqZoomer = Qwt.QwtPlotZoomer(self.gui.freqPlot.xBottom, self.gui.freqPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.freqPlot.canvas()) self.specZoomer = Qwt.QwtPlotZoomer(self.gui.specPlot.xBottom, self.gui.specPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPicker.AlwaysOn, self.gui.specPlot.canvas()) # Set up action when tab is changed self.connect(self.gui.tabGroup, Qt.SIGNAL("currentChanged (int)"), self.tabChanged) # Add a legend to the Time plot legend_real = Qwt.QwtLegend() self.gui.timePlot.insertLegend(legend_real) # Set up slider self.gui.plotHBar.setSingleStep(1) self.gui.plotHBar.setPageStep(self.block_length) self.gui.plotHBar.setMinimum(0) self.gui.plotHBar.setMaximum(self.block_length) self.connect(self.gui.plotHBar, Qt.SIGNAL("valueChanged(int)"), self.sliderMoved) # Connect Open action to Open Dialog box self.connect(self.gui.action_open, Qt.SIGNAL("activated()"), self.open_file) # Connect Reload action to reload the file self.connect(self.gui.action_reload, Qt.SIGNAL("activated()"), self.reload_file) self.gui.action_reload.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+R", None, QtGui.QApplication.UnicodeUTF8)) # Set up file position boxes to update current figure self.connect(self.gui.filePosStartLineEdit, Qt.SIGNAL("editingFinished()"), self.file_position_changed) self.connect(self.gui.filePosStopLineEdit, Qt.SIGNAL("editingFinished()"), self.file_position_changed) self.connect(self.gui.filePosLengthLineEdit, Qt.SIGNAL("editingFinished()"), self.file_length_changed) self.connect(self.gui.fileTimeStartLineEdit, Qt.SIGNAL("editingFinished()"), self.file_time_changed) self.connect(self.gui.fileTimeStopLineEdit, Qt.SIGNAL("editingFinished()"), self.file_time_changed) self.connect(self.gui.fileTimeLengthLineEdit, Qt.SIGNAL("editingFinished()"), self.file_time_length_changed) stylestr = str(self.gui.lineStyleComboBox.currentText().toAscii()) style = self.line_styles[stylestr] self.rcurve = Qwt.QwtPlotCurve("Real") self.icurve = Qwt.QwtPlotCurve("Imaginary") self.rsym = Qwt.QwtSymbol() self.rsym.setStyle(style) self.rsym.setSize(10) self.isym = Qwt.QwtSymbol() self.isym.setStyle(style) self.isym.setSize(10) self.rcurve.setSymbol(self.rsym) self.icurve.setSymbol(self.isym) self.icurve.attach(self.gui.timePlot) self.rcurve.attach(self.gui.timePlot) self.psdcurve = Qwt.QwtPlotCurve("PSD") self.psdcurve.attach(self.gui.freqPlot) # Set up specTab plot as a spectrogram self.specdata = SpectrogramData(range(0, 10), range(0, 10)) colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red) colorMap.addColorStop(0.1, Qt.Qt.cyan) colorMap.addColorStop(0.6, Qt.Qt.green) colorMap.addColorStop(0.95, Qt.Qt.yellow) self.spec = Qwt.QwtPlotSpectrogram() self.spec.setColorMap(colorMap) self.spec.attach(self.gui.specPlot) self.spec.setDisplayMode(Qwt.QwtPlotSpectrogram.ImageMode, True) self.spec.setData(self.specdata) self.rightAxis = self.gui.specPlot.axisWidget(Qwt.QwtPlot.yRight) self.rightAxis.setTitle("Magnitude (dBm)") self.rightAxis.setColorBarEnabled(True) self.rightAxis.setColorMap(self.spec.data().range(), self.spec.colorMap()) self.gui.specPlot.enableAxis(Qwt.QwtPlot.yRight) # Set up initial color scheme self.color_modes["Blue on Black"]() # When line width spin box changes, update the pen size self.connect(self.gui.lineWidthSpinBox, Qt.SIGNAL("valueChanged(int)"), self.change_pen_width) self.gui.lineWidthSpinBox.setRange(1, 10) # When style size spin box changes, update the pen size self.connect(self.gui.styleSizeSpinBox, Qt.SIGNAL("valueChanged(int)"), self.change_style_size) self.gui.styleSizeSpinBox.setRange(1, 20) self.gui.styleSizeSpinBox.setValue(5) # Connect a signal for when the sample rate changes self.set_sample_rate(self.sample_rate) self.connect(self.gui.sampleRateLineEdit, Qt.SIGNAL("editingFinished()"), self.sample_rate_changed) if(filename is not None): self.initialize(filename) self.show()
def __init__(self, *args, **kwargs): self.monitor = kwargs['monitor'] del kwargs['monitor'] self.VAR = kwargs['VAR'] del kwargs['VAR'] Qwt.QwtPlot.__init__(self, *args) self.contour = True self.__spectrogram = Qwt.QwtPlotSpectrogram() # LeftButton for the zooming # MidButton for the panning # RightButton: zoom out by 1 # Ctrl+RighButton: zoom out to full size self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOn, self.canvas()) self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect2, Qt.Qt.RightButton, Qt.Qt.ControlModifier) self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect3, Qt.Qt.RightButton) self.zoomer.setRubberBandPen(Qt.Qt.darkBlue) self.zoomer.setTrackerPen(Qt.Qt.darkBlue) if not hasattr(self, 'log'): self.log = False xmin = -10 ymin = -10 xmax = 10 ymax = 10 x_a = [] y_a = [] intes = [] for x in np.linspace(xmin, xmax, 50): for y in np.linspace(ymin, ymax, 50): x_a.append(x) y_a.append( y ) # I just used a random function from https://www.physicsforums.com/threads/cool-3-d-functions-for-graphing.140087/ to display # intes.append(x+y) # This is the actual function I used for testing. It is much simplier and you can tell where every point should be intes.append( max([ -2 * (round(math.e**(-(x * 2)**2)) + round(math.e** (-(y * 2)**2))) + 2 + 2 * math.cos((x**2 + y**2) / 4), 25 * math.e**(-1 * (x**2 + y**2) * 3) ])) self.plot(x_a, y_a, intes) panner = Qwt.QwtPlotPanner(self.canvas()) panner.setAxisEnabled(Qwt.QwtPlot.yRight, False) panner.setMouseButton(Qt.Qt.MidButton) # Avoid jumping when labels with more/less digits # appear/disappear when scrolling vertically # fm = Qt.QFontMetrics(self.axisWidget(Qwt.QwtPlot.yLeft).font()) self.axisScaleDraw(Qwt.QwtPlot.yLeft).setMinimumExtent( fm.width("100.00"))
def Seach_ZDJ(self): self.findms = [] (mz_bin, val_bin, peaks_bin) = processMS(binMS(self.ms)) peaks_bin.sort(key=lambda d: d[1], reverse=True) self.peak_index = [] self.peak_inten = [] for i in range(0, len(peaks_bin)): self.peak_index.append(int(peaks_bin[i][0])) self.peak_inten.append(peaks_bin[i][1]) if len(peaks_bin) < 10: self.findms = self.peak_index else: self.findms = self.peak_index[0:10] time0 = time.time() db = sqlite3.connect(NIST_DBPath) self.cur = db.cursor() self.cur.execute( "select id,top10peakindex from catalog where MW>%d-28 and MW<%d+28" % (self.maxmass, self.maxmass)) self.c = self.cur.fetchall() ms = [] for i in range(len(self.c)): self.basems = np.frombuffer(self.c[i][1], dtype=np.int) cor = self.comnum() if cor > 0.4: temp = (self.c[i][0], cor) ms.append(temp) print ms self.masscor = [] tic = time.time() for i in range(len(ms)): self.cur.execute( "select peakindex, peakintensity from catalog where id=%d" % (ms[i][0])) temp = self.cur.fetchall() masstemp = np.frombuffer(temp[0][0], dtype=np.int) intensitytemp = np.frombuffer(temp[0][1], dtype=np.int) temp2 = (ms[i][0], corrcoef_ms(masstemp, intensitytemp, mz_bin, val_bin)) self.masscor.append(temp2) print time.time() - time0 print time.time() - tic self.masscor.sort(key=lambda d: d[1], reverse=True) for i in range(min(25, len(ms))): self.cur.execute( "select name,Formula,MW from catalog where id=%d" % self.masscor[i][0]) temp = self.cur.fetchall() strsimilarity = '%.2f' % self.masscor[i][1] temp3 = temp[0][1][:-1] temp1 = temp[0][2] temp2 = temp[0][0][:-2] item = QTreeWidgetItem([ str(i + 1), str(strsimilarity), str(temp1), str(temp3), str(temp2) ]) self.library_list.addTopLevelItem(item) if len(ms) > 0: self.showMs(self.masscor[0][0]) zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.DragSelection, Qwt.QwtPicker.AlwaysOn, self.plot1.canvas()) zoomer.setRubberBandPen(QPen(Qt.black)) zoomer.setTrackerPen(QPen(Qt.blue)) self.plot1.zoomer = zoomer self.plot1.zoomer.setZoomBase()
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))