示例#1
0
文件: plots.py 项目: umithardal/nicos
    def initUi(self):
        # axes setup
        self.widget = InteractiveGRWidget(self)
        self.plot = Plot(viewport=(.1, .95, .25, .95))
        self.axes = NicosTimePlotAxes(self.plot._viewport)
        self.axes.setWindow(0, 1, 0, 1)
        self.plot.addAxes(self.axes)
        self.plot.setLegend(True)
        self.plot.setLegendWidth(0.07)
        self.plot.offsetXLabel = -.2
        self.axes.setXtickCallback(self.xtickCallBack)
        self.widget.addPlot(self.plot)
        layout = QHBoxLayout(self)
        layout.addWidget(self.widget)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.curves = []

        # event support
        self.widget.cbm.addHandler(LegendEvent.ROI_CLICKED,
                                   self.on_legendItemClicked, LegendEvent)
        self.widget.cbm.addHandler(MouseEvent.MOUSE_MOVE, self.on_mouseMove)

        self.timeSeriesUpdate.connect(self.on_timeSeriesUpdate)
示例#2
0
    def __init__(self, *args, **kwargs):
        QtGui.QMainWindow.__init__(self, *args, **kwargs)
        self._grw = InteractiveGRWidget()
        self.setCentralWidget(self._grw)

        viewport = [0.1, 0.88, 0.1, 0.88]

        self.curve = DependentPlotCurve([0], [0], linecolor=4)
        self.peakbars = PeakBars([], [], linecolor=2)
        self.curve.dependent = [self.peakbars]
        axes = ClampedPlotAxes(viewport, 50, 5, 1, 2)
        axes.setWindow(50, 25000, 0, 100)
        axes.addCurves(self.curve)
        plot = Plot(viewport).addAxes(axes)
        plot.title = "QtGR Power Spectrum"
        plot.subTitle = "Capturing Microphone"
        axes.scale = gr.OPTION_X_LOG
        self._grw.addPlot(plot)

        timer = QtCore.QTimer(self)
        timer.timeout.connect(self.updateData)
        timer.start(40)
示例#3
0
def main(*args):
    app = QtGui.QApplication(*args)
    grw = InteractiveGRWidget()
    viewport = [0.1, 0.88, 0.1, 0.88]

    xd = [3, 3, 10, 18, 18, 10, 10, 5, 1, 15, 20, 5, 15, 10, 7, 13, 16]
    yd = [3, 18, 18, 3, 18, 10, 1, 5, 10, 5, 10, 15, 15, 15, 20, 20, 8]
    zd = [25, 25, 25, 25, 25, -5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 25]

    axes = ContourAxes(viewport)
    axes.addCurves(PlotContour(xd, yd, zd, nx=40, ny=40))
    axes.setGrid(False)
    plot = Plot(viewport).addAxes(axes)
    plot.title = "Plot contour lines using QtGR"

    grw.addPlot(plot)
    grw.resize(QtCore.QSize(500, 500))
    grw.show()
    win = axes.getWindow()
    grw.update()

    sys.exit(app.exec_())
    def __init__(self, *args, **kwargs):
        QtGui.QMainWindow.__init__(self, *args, **kwargs)
        self._grw = InteractiveGRWidget()
        self.setCentralWidget(self._grw)

        viewport = [0.1, 0.88, 0.1, 0.88]
        x = arange(0, 2 * pi, 0.01)
        y = sin(x)

        self.curve = PlotCurve(x, y)
        axes = ScaledPlotAxes(viewport)
        axes.addCurves(self.curve)
        plot = Plot(viewport).addAxes(axes)
        plot.title = "QtGR Timer example"
        plot.subTitle = "Plotting Live-Data"
        plot.xlabel = "t"
        plot.ylabel = "sin(t)"
        plot.autoscale = PlotAxes.SCALE_X | PlotAxes.SCALE_Y
        self._grw.addPlot(plot)

        timer = QtCore.QTimer(self)
        timer.timeout.connect(self.updateData)
        timer.start(40)
示例#5
0
    def __init__(self, parent, window, timeaxis=False):
        InteractiveGRWidget.__init__(self, parent)
        NicosPlot.__init__(self, window, timeaxis=timeaxis)

        self.timeaxis = timeaxis or (self.axescls == NicosTimePlotAxes)
        self.leftTurnedLegend = True
        self.statusMessage = None
        self.mouselocation = None
        self._cursor = self.cursor()
        self._mouseSelEnabled = self.getMouseSelectionEnabled()
        self._markertype = gr.MARKERTYPE_OMARK

        dictPrintType = dict(gr.PRINT_TYPE)
        for prtype in [gr.PRINT_JPEG, gr.PRINT_TIF]:
            dictPrintType.pop(prtype)
        self._saveTypes = (";;".join(dictPrintType.values()) + ";;" +
                           ";;".join(gr.GRAPHIC_TYPE.values()))
        self._saveName = None
        self._color = ColorIndexGenerator()
        self._plot = Plot(viewport=(.1, .85, .15, .88))
        self._plot.setLegendWidth(0.05)
        self._axes = self.axescls(viewport=self._plot.viewport)
        self._axes.backgroundColor = 0
        self._plot.addAxes(self._axes)
        self._plot.title = self.titleString()
        self.addPlot(self._plot)

        guiConn = GUIConnector(self)
        guiConn.connect(LegendEvent.ROI_CLICKED, self.on_legendItemClicked,
                        LegendEvent)
        guiConn.connect(ROIEvent.ROI_CLICKED, self.on_roiItemClicked, ROIEvent)
        guiConn.connect(MouseEvent.MOUSE_PRESS, self.on_fitPicker_selected)
        guiConn.connect(MouseEvent.MOUSE_MOVE, self.on_mouseMove)
        self.logXinDomain.connect(self.on_logXinDomain)
        self.logYinDomain.connect(self.on_logYinDomain)
        self.setLegend(True)
        self.updateDisplay()
示例#6
0
def main(*args):
    app = QtWidgets.QApplication(*args)
    grw = InteractiveGRWidget()
    viewport = [0.1, 0.88, 0.1, 0.88]

    z = readfile(
        os.path.join(os.path.dirname(os.path.realpath(__file__)), "fecr.dat"))
    zd = np.asarray(z)
    xd = yd = np.arange(1, 201)

    axes = ContourAxes(viewport)
    axes.addCurves(PlotSurface(xd, yd, zd, option=gr.OPTION_CELL_ARRAY))
    axes.addCurves(PlotContour(xd, yd, zd))
    axes.setGrid(False)
    plot = Plot(viewport).addAxes(axes)
    plot.title = "Plot surface and contour lines using QtGR"

    grw.addPlot(plot)
    grw.resize(QtCore.QSize(500, 500))
    grw.show()
    win = axes.getWindow()
    grw.update()

    sys.exit(app.exec_())
示例#7
0
 def plot(self, *args, **kwargs):
     plot = Plot()
     axes = PlotAxes(plot.viewport)
     axes.plot(*args, **kwargs)
     plot.addAxes(axes)
     return self.addPlot(plot)
示例#8
0
if __name__ == "__main__":
    import sys
    from gr import pygr
    logging.basicConfig(level=logging.CRITICAL)
    for name in [__name__, pygr.base.__name__, pygr.__name__]:
        logging.getLogger(name).setLevel(logging.DEBUG)
    app = QtGui.QApplication(sys.argv)
    grw = InteractiveGRWidget()
    grw.resize(QtCore.QSize(500, 500))
    viewport = [0.1, 0.9, 0.1, 0.88]

    x = [-3.3 + t * .1 for t in range(66)]
    y = [t**5 - 13 * t**3 + 36 * t for t in x]

    n = 100
    pi2_n = 2. * math.pi / n
    x2 = [i * pi2_n for i in range(0, n + 1)]
    y2 = map(lambda xi: math.sin(xi), x2)

    plot = Plot(viewport).addAxes(PlotAxes().plot(x, y),
                                  PlotAxes().plot(x2, y2))
    plot.title, plot.subTitle = "foo", "bar"
    plot.xlabel, plot.ylabel = "x", "f(x)"

    grw.addPlot(plot)
    grw.show()
    grw.update()

    sys.exit(app.exec_())
示例#9
0
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                "qtgrdemo.ui"), self)

        dictPrintType = dict(gr.PRINT_TYPE)
        map(dictPrintType.pop, [gr.PRINT_JPEG, gr.PRINT_TIF])
        self._saveTypes = (";;".join(dictPrintType.values()) + ";;" +
                           ";;".join(gr.GRAPHIC_TYPE.values()))
        self._saveName = None
        self._title = unicode(self.windowTitle())
        self._startupTime = time.time()

        self._chkLogX.stateChanged.connect(self._logXClicked)
        self._chkLogY.stateChanged.connect(self._logYClicked)
        self._chkGrid.stateChanged.connect(self._gridClicked)
        self._chkErr.stateChanged.connect(self._errorsClicked)
        self._chkKeepRatio.stateChanged.connect(self._keepRatioClicked)
        self._btnReset.clicked.connect(self._resetClicked)
        self._btnPick.clicked.connect(self._pickClicked)
        self._shell.returnPressed.connect(self._shellEx)
        self._actionSave.triggered.connect(self.save)
        self._actionPrint.triggered.connect(self.printGR)
        self._gr.logXinDomain.connect(self._logXinDomain)
        self._gr.logYinDomain.connect(self._logYinDomain)
        self._gr.modePick.connect(self._pickModeChanged)

        guiConn = GUIConnector(self._gr)
        guiConn.connect(MouseEvent.MOUSE_MOVE, self.mouseMoveGr)
        guiConn.connect(PickEvent.PICK_PRESS, self.pointPickGr)
        guiConn.connect(LegendEvent.ROI_CLICKED, self.legendClick)
        guiConn.connect(LegendEvent.ROI_OVER, self.legendOver)

        x = [-3.3 + t * .1 for t in range(66)]
        y = [t ** 5 - 13 * t ** 3 + 36 * t for t in x]
        x2 = [-3.5 + i * .5 for i in range(0, 15)]
        y2 = x2

        dneg = map(lambda y: y - 0.25 * abs(y), y)
        dpos = map(lambda y: y + 0.25 * abs(y), y)
        self._errBar = ErrorBar(x, y, dneg, dpos)

        self._curveFoo = PlotCurve(x, y, legend="foo bar")
        axes = PlotAxes().addCurves(self._curveFoo)
        axes.setXtickCallback(self._xtickCallBack)
        self._plot = Plot((.1, .92, .2, .88)).addAxes(axes,
                                    PlotAxes(drawX=False).plot(x2, y2))
        self._plot.offsetXLabel = -.1
        self._plot2 = Plot((.1, .95, .15, .88)).addAxes(PlotAxes().addCurves(PlotCurve(x2, y2,
                                                           legend="second")))

        self._plot.title = "QtGR Demo"
        self._plot.subTitle = "Multiple Axes Example"
        self._plot.xlabel = "x"
        self._plot.ylabel = "f(x)"
        self._plot.setLegend(True)
        self._gr.addPlot(self._plot)

        self._plot2.title = "Second Widget"
        self._plot2.subTitle = "Linear Example (less interactive)"
        self._plot2.xlabel = "x2"
        self._plot2.ylabel = "f2(x2)"
        self._plot2.setLegend(True)
        self._plot2.setGrid(False)
        self._gr2.addPlot(self._plot2)
示例#10
0
        logging.getLogger(name).setLevel(logging.DEBUG)
    app = QApplication(sys.argv)
    grw = InteractiveGRWidget()
    grw.resize(QtCore.QSize(500, 500))
    viewport = [0.1, 0.45, 0.1, 0.88]
    vp2 = [.6, .95, .1, .88]

    x = [-3.3 + t * .1 for t in range(66)]
    y = [t ** 5 - 13 * t ** 3 + 36 * t for t in x]

    n = 100
    pi2_n = 2.*math.pi / n
    x2 = [i * pi2_n for i in range(0, n + 1)]
    y2 = map(lambda xi: math.sin(xi), x2)

    plot = Plot(viewport).addAxes(PlotAxes(viewport).plot(x, y),
                                  PlotAxes(viewport).plot(x2, y2))
    plot.title, plot.subTitle = "foo", "bar"
    plot.xlabel, plot.ylabel = "x", "f(x)"

    plot2 = Plot(vp2).addAxes(PlotAxes(vp2).plot(x2, y2))
    plot2.title, plot2.subTitle = "Title", "Subtitle"
    plot2.xlabel = "x"

    grw.addPlot(plot)
    grw.addPlot(plot2)
    grw.show()
    grw.update()

    sys.exit(app.exec_())
示例#11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Draw text at an arbitrary position on the Axes using gr.pygr.
"""

import gr
from gr.pygr import Plot, PlotAxes, PlotCurve, Text

tx, ty = 0, -20
x = [-3.3 + t * .1 for t in range(66)]
y = [t**5 - 13 * t**3 + 36 * t for t in x]
txtfmt = "Text drawn on\n(%g, %g) with\nhalign left, valign top"

plt = Plot((.1, .95, .1, .88))
plt.title = "Text on Axes Example"
plt.subTitle = "Show usage of gr.pygr.Text"
plt.xlabel = "x"
plt.ylabel = "y"

curve = PlotCurve(x, y, legend="foo bar")
axes = PlotAxes(plt.viewport).addCurves(curve)
axes.setWindow(-4.0, 4.0, -60.0, 40.0)
text = Text(tx, -ty, txtfmt % (tx, -ty), axes, .02)
plt.addAxes(axes)
text2 = Text(tx, ty, txtfmt % (tx, ty), axes, .02)
tbx, tby = text2.getBoundingBox()

plt.drawGR()
text.drawGR()
text2.drawGR()