class QwtPlotE(QwtPlot):
    """a slightly enhanced version of QwtPlot which already has some sugar on it"""
    def __init__(self, *arg):
        QwtPlot.__init__(self, *arg)
        self.plotLayout().setAlignCanvasToScales(True)
        self.setCanvasBackground(Qt.white)
        self.legend = QwtLegend()
        self.legend.setItemMode(QwtLegend.ClickableItem)
        self.insertLegend(self.legend, QwtPlot.TopLegend)
        self.grid = QwtPlotGrid()
        self.grid.attach(self)
        self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine))
        self.zoomer = QwtPlotZoomer(QwtPlot.xBottom, QwtPlot.yLeft, QwtPicker.DragSelection,
            QwtPicker.AlwaysOn, self.canvas())
        self.zoomer.setRubberBandPen(QPen(Qt.green))
        self.zoomer.setTrackerPen(QPen(Qt.red))
        self.magnifier = QwtPlotMagnifier(self.canvas())
        self.panner = QwtPlotPanner(self.canvas())
        self.panner.setMouseButton(Qt.LeftButton, Qt.ControlModifier)
        self.connect(self, SIGNAL("legendClicked(QwtPlotItem*)"), self.togglePlotItemVisibility)

    def togglePlotItemVisibility(self, plotItem):
        """Toggle the visibility of a plot item"""
        plotItem.setVisible(not plotItem.isVisible())
        self.replot()
Esempio n. 2
0
    def __init__(self, spurset, fef, parent):
        chart.__init__(self, spurset, fef, parent)
        self.plot = QwtPlot(parent)

        self.plot.setAxisScale(xaxis, self.spurset.RFmin, self.spurset.RFmax)
        self.plot.setAxisScale(yaxis, -self.spurset.dspan / 2,
                               self.spurset.dspan / 2)

        self.plot.setCanvasBackground(Qt.white)
        grid = QwtPlotGrid()
        grid.setMajPen(QPen(Qt.black, 1, Qt.DotLine))
        grid.attach(self.plot)

        self.plot.insertLegend(QwtLegend(self.parent), QwtPlot.ExternalLegend)

        # a picker to be used for the front-end filter parallelogram
        self.picker = QwtPlotPicker(xaxis, yaxis, QwtPicker.PointSelection,
                                    QwtPlotPicker.NoRubberBand,
                                    QwtPicker.AlwaysOff, self.plot.canvas())
        # gonna need this to implement ondrop()
        self._mouseRelease = self.picker.widgetMouseReleaseEvent
        self._picked_obj = None

        self.picker.connect(self.picker, SIGNAL('appended(const QPoint&)'),
                            self.onpick)
        self.picker.connect(self.picker, SIGNAL('moved(const QPoint&)'),
                            self.ondrag)
        # all about the monkey-patching
        self.picker.widgetMouseReleaseEvent = self.ondrop
 def __init__(self, parent):
     QwtPlot.__init__(self, parent)
     self.variables = []
     self.insertLegend(QwtLegend(self), QwtPlot.TopLegend)
     self.setCanvasBackground(Qt.white)
     self.magnifier = QwtPlotMagnifier(self.canvas())
     self.magnifier.setAxisEnabled(QwtPlot.xBottom, False)
     self.magnifier.setAxisEnabled(QwtPlot.yLeft, True)
     self.panner = QwtPlotPanner(self.canvas())
     self.panner.setAxisEnabled(QwtPlot.xBottom, False)
     self.panner.setAxisEnabled(QwtPlot.yLeft, True)
 def add_plot(self, name, units):
     # legend
     legend = QwtLegend()
     legend.setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Sunken)
     legend.setItemMode(QwtLegend.ClickableItem)
     # plot
     plot = QwtPlot(self)
     plot.setTitle(name.upper())
     plot.setObjectName(name)
     plot.setCanvasBackground(Qt.Qt.white)
     plot.setAxisTitle(QwtPlot.xBottom, "time [s]")
     plot.insertLegend(legend, QwtPlot.RightLegend)
     plot.time = deque(maxlen=MAX_LENGTH)
     plot.data = []
     plot.curves = []
     for i, unit in enumerate(units):
         position = QwtPlot.yLeft if i == 0 else QwtPlot.yRight
         curve = QwtPlotCurve(LEGENDS[unit])
         curve.setPen(Qt.QPen(self.next_color(), 2))
         curve.setYAxis(position)
         curve.attach(plot)
         plot.enableAxis(position)
         plot.setAxisTitle(position, unit)
         plot.curves.append(curve)
         plot.data.append(deque(maxlen=MAX_LENGTH))
     self.vertical_layout.addWidget(plot)
     self._plots[name] = plot
Esempio n. 5
0
    def outTIF(self, plotWidget, d_folder, name, title):
        if d_folder:
            fileName = os.path.join(d_folder, name + '.tif')
        else:
            if self.settings.value('lastOutputDir'):
                folder = self.settings.value('lastOutputDir')
            else:
                folder = self.settings.value('projFolder')

            fileName = QFileDialog.getSaveFileName(
                caption="Save Plot As .tif file",
                directory=folder,
                filter="Tagged Image File Format (*.tif;*.tiff)")
        fileName = toUnicode(fileName)

        if fileName:
            if not title:
                title = self.settings.value('figureTitle')
            plotWidget.setTitle(title)
            pix = QPixmap(QSize(600, 400))
            sh = QBrush(pix)
            sh.setColor(Qt.white)
            sh.setStyle(Qt.SolidPattern)
            painter = QPainter()
            painter.begin(pix)
            painter.setBrush(sh)
            painter.drawRect(0, 0, 600, 400)
            painter.end()

            legend = QwtLegend()
            plotWidget.insertLegend(legend)
            plotWidget.setAxisTitle(QwtPlot.xBottom,
                                    self.settings.value('xAxisTitle'))
            plotWidget.setAxisTitle(QwtPlot.yLeft,
                                    self.settings.value('yAxisTitle'))

            QSettings().setValue("lastOutputDir", os.path.dirname(fileName))
            filter = QwtPlotPrintFilter()
            filter.setOptions(QwtPlotPrintFilter.PrintAll
                              & ~QwtPlotPrintFilter.PrintBackground)
            plotWidget.print_(pix, filter)
            pix.save(fileName)
            plotWidget.insertLegend(None)
            plotWidget.setAxisTitle(QwtPlot.xBottom, None)
            plotWidget.setAxisTitle(QwtPlot.yLeft, None)
            plotWidget.setTitle(None)
 def __init__(self, *arg):
     QwtPlot.__init__(self, *arg)
     self.plotLayout().setAlignCanvasToScales(True)
     self.setCanvasBackground(Qt.white)
     self.legend = QwtLegend()
     self.legend.setItemMode(QwtLegend.ClickableItem)
     self.insertLegend(self.legend, QwtPlot.TopLegend)
     self.grid = QwtPlotGrid()
     self.grid.attach(self)
     self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine))
     self.zoomer = QwtPlotZoomer(QwtPlot.xBottom, QwtPlot.yLeft, QwtPicker.DragSelection,
         QwtPicker.AlwaysOn, self.canvas())
     self.zoomer.setRubberBandPen(QPen(Qt.green))
     self.zoomer.setTrackerPen(QPen(Qt.red))
     self.magnifier = QwtPlotMagnifier(self.canvas())
     self.panner = QwtPlotPanner(self.canvas())
     self.panner.setMouseButton(Qt.LeftButton, Qt.ControlModifier)
     self.connect(self, SIGNAL("legendClicked(QwtPlotItem*)"), self.togglePlotItemVisibility)
Esempio n. 7
0
    def outSVG(self, plotWidget, d_folder, name, title):
        if d_folder:
            fileName = os.path.join(d_folder, name + '.svg')
        else:
            if self.settings.value('lastOutputDir'):
                folder = self.settings.value('lastOutputDir')
            else:
                folder = self.settings.value('projFolder')

            fileName = QFileDialog.getSaveFileName(
                caption="Save Plot As .svg file",
                directory=folder,
                filter="Scalable Vector Graphics(*.svg)")
        fileName = toUnicode(fileName)

        if fileName:
            pix = QSvgGenerator()
            pix.setFileName(fileName)
            pix.setSize(QSize(600, 400))

            if not title:
                title = self.settings.value('figureTitle')
            plotWidget.setTitle(title)
            legend = QwtLegend()
            plotWidget.insertLegend(legend)
            plotWidget.setAxisTitle(QwtPlot.xBottom,
                                    self.settings.value('xAxisTitle'))
            plotWidget.setAxisTitle(QwtPlot.yLeft,
                                    self.settings.value('yAxisTitle'))

            QSettings().setValue("lastOutputDir", os.path.dirname(fileName))
            filter = QwtPlotPrintFilter()
            filter.setOptions(QwtPlotPrintFilter.PrintAll
                              & ~QwtPlotPrintFilter.PrintBackground)
            plotWidget.print_(pix, filter)
            plotWidget.insertLegend(None)
            plotWidget.setAxisTitle(QwtPlot.xBottom, None)
            plotWidget.setAxisTitle(QwtPlot.yLeft, None)
            plotWidget.setTitle(None)