def __drawParetoChart(self):
        def make_noise(value, noise_size):
            return value + (noise_size / -2 + noise_size * random.random())

        self.__pareto_chart.removeAllSeries()

        series1 = QScatterSeries()
        series1.setMarkerShape(QScatterSeries.MarkerShapeCircle)
        series1.setMarkerSize(5)
        series1.append(make_noise(23, 2), make_noise(25, 2))
        series1.setBrush(QColor(Qt.red))
        self.__pareto_chart.addSeries(series1)
        self.__axisy.setRange(0.0, 100.0)

        series3 = QScatterSeries()
        series3.setName("Точка утопии")
        series3.setMarkerShape(QScatterSeries.MarkerShapeCircle)
        series3.setMarkerSize(10)
        series3.append(make_noise(2, 0.5), make_noise(23, 2))
        self.__pareto_chart.addSeries(series3)

        series2 = QScatterSeries()
        series2.setName("Оптимальный")
        series2.setMarkerShape(QScatterSeries.MarkerShapeCircle)
        series2.setMarkerSize(7)
        series2.append(make_noise(2, 0.5), make_noise(45, 4))
        self.__pareto_chart.addSeries(series2)

        self.__pareto_chart.setAxisX(self.__axisx, series1)
        self.__pareto_chart.setAxisY(self.__axisy, series1)
        self.__pareto_chart.setAxisX(self.__axisx, series2)
        self.__pareto_chart.setAxisY(self.__axisy, series2)
        self.__pareto_chart.setAxisX(self.__axisx, series3)
        self.__pareto_chart.setAxisY(self.__axisy, series3)
Esempio n. 2
0
   def __createChart(self):  ##创建图表
      chart = QChart()  #创建 Chart
   ##      chart.setTitle("简单函数曲线")
      chart.legend().setVisible(True)
      self.chartView.setChart(chart)   #Chart添加到chartView

      pen=QPen()
      pen.setWidth(2)

   ##========LineSeries折线 和 ScatterSeries散点
      seriesLine = QLineSeries()
      seriesLine.setName("LineSeries折线")
      seriesLine.setPointsVisible(False)     #数据点不可见
      pen.setColor(Qt.red)
      seriesLine.setPen(pen)
      seriesLine.hovered.connect(self.do_series_hovered)    #信号 hovered
      seriesLine.clicked.connect(self.do_series_clicked)    #信号 clicked
      chart.addSeries(seriesLine)   #添加到chart

      seriesLinePoint = QScatterSeries()    #散点序列
      seriesLinePoint.setName("ScatterSeries散点")
      shape=QScatterSeries.MarkerShapeCircle  #MarkerShapeRectangle
      seriesLinePoint.setMarkerShape(shape)   #散点形状,只有2种
      seriesLinePoint.setBorderColor(Qt.yellow)
      seriesLinePoint.setBrush(QBrush(Qt.red))
      seriesLinePoint.setMarkerSize(10)      #散点大小
      seriesLinePoint.hovered.connect(self.do_series_hovered)  #信号 hovered
      seriesLinePoint.clicked.connect(self.do_series_clicked)  #信号 clicked
      chart.addSeries(seriesLinePoint)    #添加到chart

   ##======== SplineSeries 曲线和 QScatterSeries 散点
      seriesSpLine = QSplineSeries()
      seriesSpLine.setName("SplineSeries曲线")
      seriesSpLine.setPointsVisible(False)    #数据点不可见
      pen.setColor(Qt.blue)
      seriesSpLine.setPen(pen)
      seriesSpLine.hovered.connect(self.do_series_hovered)  #信号 hovered
      seriesSpLine.clicked.connect(self.do_series_clicked)  #信号 clicked


      seriesSpPoint = QScatterSeries()    #散点序列
      seriesSpPoint.setName("QScatterSeries")
      shape=QScatterSeries.MarkerShapeRectangle  #MarkerShapeCircle
      seriesSpPoint.setMarkerShape(shape) #散点形状,只有2种
      seriesSpPoint.setBorderColor(Qt.green)
      seriesSpPoint.setBrush(QBrush(Qt.blue))
      seriesSpPoint.setMarkerSize(10)     #散点大小
      seriesSpPoint.hovered.connect(self.do_series_hovered) #信号 hovered
      seriesSpPoint.clicked.connect(self.do_series_clicked) #信号 clicked

      chart.addSeries(seriesSpLine)
      chart.addSeries(seriesSpPoint)

   ##  创建缺省坐标轴
      chart.createDefaultAxes()  #创建缺省坐标轴并与序列关联
      chart.axisX().setTitleText("time(secs)")
      chart.axisX().setRange(0,10)
      chart.axisX().applyNiceNumbers()

      chart.axisY().setTitleText("value")
      chart.axisY().setRange(-2,2)
      chart.axisY().applyNiceNumbers()

      for marker in chart.legend().markers():  #QLegendMarker类型列表
         marker.clicked.connect(self.do_LegendMarkerClicked)
Esempio n. 3
0
class Window(QMainWindow):
    def __init__(self, landmarkPoints, allPoints, threadEvent):
        super().__init__()
        self.title = "Lidar data points"
        #self.queue = queue
        self.color = Qt.darkRed
        self.lmrkPoints = landmarkPoints
        self.allPoints = allPoints
        self.event = threadEvent
        self.left = 500
        self.top = 500
        self.height = 480
        self.width = 640
        self.count = 0
        self.time = 0

        self.label = QLabel(self)
        self.lmrkBox = QCheckBox("Landmark points", self)
        self.ptsBox = QCheckBox("Data points", self)

        self.boxArea = QWidget()
        self.mainLayout = QGridLayout()
        self.mainLayout.addWidget(self.lmrkBox, 0, 0)
        self.mainLayout.addWidget(self.ptsBox, 1, 0)
        self.mainLayout.setVerticalSpacing(5)
        self.boxArea.setLayout(self.mainLayout)
        crote = QDockWidget("Hide", self)
        crote.setWidget(self.boxArea)
        self.addDockWidget(Qt.LeftDockWidgetArea, crote)

        dock = QDockWidget("", self)
        dock.setWidget(self.label)
        self.addDockWidget(Qt.LeftDockWidgetArea, dock)

        self.chart = QChart()
        self.config_axis()
        self.series = QScatterSeries(self.chart)
        self.allSeries = QScatterSeries(self.chart)
        self.config_series()
        #self.update()
        self.timer = QTimer(self)
        self.view = QChartView(self.chart)
        self.setCentralWidget(
            self.view
        )  # It is needed to create to view because the CentralWidget needs to be a QWidget, and a QChart is not so.
        self.initWindow()

    def config_series(self):
        self.series.setName("Landmark Points")
        self.allSeries.setName("Data Points")

        lmrkPen = self.series.pen()
        pen = self.allSeries.pen()
        lmrkPen.setWidthF(.2)
        pen.setWidthF(.2)
        self.series.setPen(lmrkPen)
        self.allSeries.setPen(pen)

        self.series.setColor(Qt.red)
        self.allSeries.setColor(Qt.blue)

        self.series.setMarkerShape(1)  # 1 - rectangle; 0 - circle

        # for good visualization, the landmark points should be bigger than normal points

        self.series.setMarkerSize(8)
        self.allSeries.setMarkerSize(5)
        self.label.move(15, 15)

    def config_axis(self):
        self.xAxis = QValueAxis()
        self.yAxis = QValueAxis()
        self.xAxis.setRange(-XRANGE, XRANGE)
        self.xAxis.setTitleText("Eixo x")
        self.yAxis.setRange(-YRANGE, YRANGE)
        self.yAxis.setTitleText("Eixo y")
        self.chart.addAxis(self.xAxis, Qt.AlignBottom)
        self.chart.addAxis(self.yAxis, Qt.AlignLeft)

    def update(self):
        self.event.wait()
        start = time.time()
        self.label.setText("FPS: {:.2f}".format(1 / (time.time() - self.time)))
        self.time = time.time()
        if self.count == 0 and self.lmrkPoints != []:
            self.series.append(self.lmrkPoints[0][:])
            self.allSeries.append(self.allPoints[0][:])
            del self.lmrkPoints[:]
            del self.allPoints[:]
            self.count = 1
        elif self.lmrkPoints != []:
            self.series.replace(self.lmrkPoints[0][:])
            self.allSeries.replace(self.allPoints[0][:])
            del self.lmrkPoints[:]
            del self.allPoints[:]
        end = time.time()
        self.event.clear()

    def hide_show_points(self):
        self.series.setVisible(not self.series.isVisible())

    def hide_show_all_points(self):
        self.allSeries.setVisible(not self.allSeries.isVisible())

    def initWindow(self):
        print("queue inside myWindow: {}".format(self.lmrkPoints))
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.setWindowTitle(self.title)
        self.chart.addSeries(self.series)
        self.chart.addSeries(self.allSeries)
        self.series.attachAxis(self.xAxis)
        self.series.attachAxis(self.yAxis)
        self.allSeries.attachAxis(self.xAxis)
        self.allSeries.attachAxis(self.yAxis)

        self.timer.timeout.connect(self.update)
        self.lmrkBox.stateChanged.connect(self.hide_show_points)
        self.ptsBox.stateChanged.connect(self.hide_show_all_points)

        self.timer.start(0)
        self.show()