当前位置: 首页>>代码示例>>Python>>正文


Python QwtPlot.insertLegend方法代码示例

本文整理汇总了Python中PyQt4.Qwt5.QwtPlot.insertLegend方法的典型用法代码示例。如果您正苦于以下问题:Python QwtPlot.insertLegend方法的具体用法?Python QwtPlot.insertLegend怎么用?Python QwtPlot.insertLegend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.Qwt5.QwtPlot的用法示例。


在下文中一共展示了QwtPlot.insertLegend方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_plot

# 需要导入模块: from PyQt4.Qwt5 import QwtPlot [as 别名]
# 或者: from PyQt4.Qwt5.QwtPlot import insertLegend [as 别名]
 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
开发者ID:nikinikiniki,项目名称:libsensors-python,代码行数:29,代码来源:streaming_plot_client.py

示例2: qwtchart

# 需要导入模块: from PyQt4.Qwt5 import QwtPlot [as 别名]
# 或者: from PyQt4.Qwt5.QwtPlot import insertLegend [as 别名]
class qwtchart(chart):
    colours = {'red'    : Qt.red,
               'green'  : Qt.green,
               'blue'   : Qt.blue,
               'yellow' : Qt.yellow,
               'magenta': Qt.magenta,
               'black'  : Qt.black}
    styles = {'-' : Qt.SolidLine,
              '--': Qt.DashLine,
              ':' : Qt.DotLine,
              '-.': Qt.DashDotLine}

    def getPen(self, colour, style):
        return QPen(self.colours[colour], 1, self.styles[style])

    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 redraw(self):
        xscale = self.plot.axisScaleDiv(xaxis)
        yscale = self.plot.axisScaleDiv(yaxis)
        #TODO check if it hurts to just set the scales every time, as in mpl
        if (xscale.lowerBound() != self.spurset.RFmin or
            xscale.upperBound() != self.spurset.RFmax):
            self.plot.setAxisScale(xaxis, self.spurset.RFmin,
                                   self.spurset.RFmax)
        if (yscale.lowerBound() != -self.spurset.dspan/2 or
            yscale.upperBound() != self.spurset.dspan/2):
            self.plot.setAxisScale(yaxis, -self.spurset.dspan/2,
                                   self.spurset.dspan/2)
        self.plot.replot()

    def mkline(self, xdata, ydata, style=('black','-'), title=''):
        line = QwtPlotCurve(title)
        if title is '':
            # don't display it in the legend
            # kind of ugly, that the title variable is doing double duty
            line.setItemAttribute(QwtPlotItem.Legend, False)
        pen = self.getPen(*style)
        line.setPen(pen)
        line.setRenderHint(QwtPlotItem.RenderAntialiased)
        line.setData(xdata, ydata)
        return line

    def add_line(self, line):
        line.attach(self.plot)

    def del_line(self, line):
        line.detach()

    def legend(self):
        return self.plot.legend()

    def _xval(self, pos):
        # from a QPoint referring to a pixel on the plot, find the x value
        return self.plot.invTransform(xaxis, pos.x())

    def _yval(self, pos):
        # from a QPoint referring to a pixel on the plot, find the y value
        return self.plot.invTransform(yaxis, pos.y())

    def onpick(self, pos):
        # for now, we only worry about picking the two vertical lines of the
        # front-end filter parallelogram. Other clicks are no-ops.
        if abs(pos.x() - self.plot.transform(xaxis, self.fef.start)) <= 10:
            # TODO check pos.y() as well
            self._picked_obj = self.fef.startline
            self.pick(self.fef.startline, self._xval(pos), self._yval(pos))
        elif abs(pos.x() - self.plot.transform(xaxis, self.fef.stop)) <= 10:
            self._picked_obj  = self.fef.stopline
#.........这里部分代码省略.........
开发者ID:patrickyeon,项目名称:spurdist,代码行数:103,代码来源:qwtchart.py


注:本文中的PyQt4.Qwt5.QwtPlot.insertLegend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。