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)
示例#2
0
    def setupChart(self):
        """Set up the GUI's series and chart."""
        # Collect x and y data values from the CSV file
        x_values, y_values = self.loadCSVFile()

        # Get the largest x and y values; Used for setting the chart's axes
        x_max, y_max = max(x_values), max(y_values)

        # Create numpy arrays from the x and y values
        x_values = np.array(x_values)
        y_values = np.array(y_values)

        # Calculate the regression line
        coefficients = linearRegression(x_values, y_values)

        # Create chart object
        chart = QChart()
        chart.setTitle("Auto Insurance for Geographical Zones in Sweden")
        chart.legend().hide()

        # Create scatter series and add points to the series
        scatter_series = QScatterSeries()
        scatter_series.setName("DataPoints")
        scatter_series.setMarkerSize(9.0)
        scatter_series.hovered.connect(self.displayPointInfo)

        for value in range(0, self.row_count - 1):
            scatter_series.append(x_values[value], y_values[value])
            scatter_series.setBorderColor(QColor('#000000'))

        # Create line series and add points to the series
        line_series = QLineSeries()
        line_series.setName("RegressionLine")

        # Calculate the regression line
        for x in x_values:
            y_pred = coefficients[0] + coefficients[1] * x
            line_series.append(x, y_pred)

        # Add both series to the chart and create x and y axes
        chart.addSeries(scatter_series)
        chart.addSeries(line_series)
        chart.createDefaultAxes()

        axis_x = chart.axes(Qt.Horizontal)
        axis_x[0].setTitleText("Number of Claims")
        axis_x[0].setRange(0, x_max)
        axis_x[0].setLabelFormat("%i")

        axis_y = chart.axes(Qt.Vertical)
        axis_y[0].setTitleText(
            "Total Payment in Swedish Kronor (in thousands)")
        axis_y[0].setRange(0, y_max + 20)

        # Create QChartView object for displaying the chart
        chart_view = QChartView(chart)

        v_box = QVBoxLayout()
        v_box.addWidget(chart_view)
        self.setLayout(v_box)
示例#3
0
文件: test.py 项目: 524836851/RT_GUI
class ChartView(QChartView,QChart):
    def __init__(self, *args, **kwargs):
        super(ChartView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        self.setRenderHint(QPainter.Antialiasing)  # 抗锯齿
        self.chart_init()
        self.timer_init()
    def timer_init(self):
        #使用QTimer,2秒触发一次,更新数据
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.drawLine)
        self.timer.start(100)
    def chart_init(self):
        self.chart = QChart()
        self.series = QScatterSeries()
        #设置曲线名称
        self.series.setName("实时数据")
        self.series.setColor(QColor(255,0,0))
        self.series.setMarkerSize(20.0)
        self.series.setPen(QPen(QtCore.Qt.PenStyle.NoPen))
        #把曲线添加到QChart的实例中
        self.chart.addSeries(self.series)
        #声明并初始化X轴,Y轴
        self.dtaxisX = QDateTimeAxis()
        self.vlaxisY = QValueAxis()
        #设置坐标轴显示范围
        self.dtaxisX.setMin(QDateTime.currentDateTime().addSecs(-300*1))
        self.dtaxisX.setMax(QDateTime.currentDateTime().addSecs(0))
        self.vlaxisY.setMin(0)
        self.vlaxisY.setMax(1500)
        #设置X轴时间样式
        self.dtaxisX.setFormat("MM月dd hh:mm:ss")
        #设置坐标轴上的格点
        self.dtaxisX.setTickCount(6)
        self.vlaxisY.setTickCount(11)
        #设置坐标轴名称
        self.dtaxisX.setTitleText("时间")
        self.vlaxisY.setTitleText("量程")
        #设置网格不显示`
        #把坐标轴添加到chart中
        self.chart.addAxis(self.dtaxisX,Qt.AlignBottom)
        self.chart.addAxis(self.vlaxisY,Qt.AlignLeft)
        #把曲线关联到坐标轴
        self.series.attachAxis(self.dtaxisX)
        self.series.attachAxis(self.vlaxisY)

        self.setChart(self.chart)
    def drawLine(self):
        #获取当前时间
        bjtime = QDateTime.currentDateTime()
        #更新X轴坐标
        self.dtaxisX.setMin(QDateTime.currentDateTime().addSecs(-300*1))
        self.dtaxisX.setMax(QDateTime.currentDateTime().addSecs(0))
        #当曲线上的点超出X轴的范围时,移除最早的点
        if(self.series.count()>149):
            self.series.removePoints(0,self.series.count()-149)
        #产生随即数
        yint = random.randint(0,1500)
        #添加数据到曲线末端
        self.series.append(bjtime.toMSecsSinceEpoch(),yint)
示例#4
0
    def getSeries(self, chart):
        for i, data_list in enumerate(self.m_dataTable):
            series = QScatterSeries(chart)
            for value, _ in data_list:
                series.append(value)

            series.setName('Series ' + str(i))
            chart.addSeries(series)
示例#5
0
    def addSeries(self, _x2idx: typing.Dict, _idx2x: list, _chart: QChart,
                  _axis_x: QValueAxis, _axis_y: QValueAxis):
        series = QScatterSeries()
        series.setName(self.name)
        for x, y in zip(self.x_list, self.y_list):
            series.append(_x2idx[x], y)
        if self.color is not None:
            series.setColor(self.color)

        _chart.addSeries(series)
        _chart.setAxisX(_axis_x, series)
        _chart.setAxisY(_axis_y, series)

        if self.show_value:
            self.createShow()
示例#6
0
    def createScatterChart(self):
        chart = QChart()
        chart.setTitle("Scatter chart")

        for i, data_list in enumerate(self.m_dataTable):
            series = QScatterSeries(chart)
            for value, _ in data_list:
                series.append(value)

            series.setName("Series " + str(i))
            chart.addSeries(series)

        chart.createDefaultAxes()

        return chart
    def createScatterChart(self):
        chart = QChart()
        chart.setTitle("Scatter chart")

        for i, data_list in enumerate(self.m_dataTable):
            series = QScatterSeries(chart)
            for value, _ in data_list:
                series.append(value)

            series.setName("Series " + str(i))
            chart.addSeries(series)

        chart.createDefaultAxes()

        return chart
示例#8
0
    def addSeries(
            self, _x2idx: typing.Dict, _idx2x: list, _chart: QChart,
            _axis_x: QValueAxis, _axis_y: QValueAxis
    ):
        series = QScatterSeries()
        series.setName(self.name)
        for x, y in zip(self.x_list, self.y_list):
            series.append(_x2idx[x], y)
        if self.color is not None:
            series.setColor(self.color)

        _chart.addSeries(series)
        _chart.setAxisX(_axis_x, series)
        _chart.setAxisY(_axis_y, series)

        if self.show_value:
            self.createShow()
示例#9
0
def XScatterSeries(data_dict, key_order = None, xkey = None, openGL=False):
    '''
    the first dict in the key_order will be used as the x-axis
    '''
    if key_order==None:
        key_order = data_dict.keys()

    series = []
    if xkey == None:
        xkey = list(key_order)[0]
    for key in key_order-xkey:
        set = QScatterSeries(); set.setName(key)
        if openGL:
            set.setUseOpenGL(True)
        for i, (itemx, itemy) in enumerate(zip_longest(data_dict[xkey],data_dict[key])):
            set.append(itemx, itemy)

        series.append(set)
    return series
示例#10
0
    def appendScatterSeries(self, name, list_x, list_y):
        ls = QScatterSeries()
        ls.setName(name)
        self.series.append(ls)
        for i in range(len(list_x)):
            x = float(list_x[i])
            y = float(list_y[i])
            ls.append(x, y)

            if self.maxy == None:  #Gives first maxy and miny
                self.maxy = y * 1.01
                self.miny = y * 0.99
                self.maxx = x * 1.01
                self.minx = x * 0.99

            if y > self.maxy:
                self.maxy = y
            if y < self.miny:
                self.miny = y
            if x > self.maxx:
                self.maxx = x
            if x < self.minx:
                self.minx = x
示例#11
0
            axis.setRange(min, max)

        newChart.setTitle(oldChart.title())
        self.setChart(newChart)


app = QApplication(sys.argv)

ANGULAR_MIN = -100
ANGULAR_MAX = 100

RADIAL_MIN = -100
RADIAL_MAX = 100

series1 = QScatterSeries()
series1.setName("scatter")
for i in range(ANGULAR_MIN, ANGULAR_MAX + 1, 10):
    series1.append(i, (float(i) / RADIAL_MAX) * RADIAL_MAX + 8.0)

series2 = QSplineSeries()
series2.setName("spline")
for i in range(ANGULAR_MIN, ANGULAR_MAX + 1, 10):
    series2.append(i, (float(i) / RADIAL_MAX) * RADIAL_MAX)

series3 = QLineSeries()
series3.setName("star outer")
ad = (ANGULAR_MAX - ANGULAR_MIN) / 8.0
rd = (RADIAL_MAX - RADIAL_MIN) / 3.0 * 1.3
series3.append(ANGULAR_MIN, RADIAL_MAX)
series3.append(ANGULAR_MIN + ad * 1, RADIAL_MIN + rd)
series3.append(ANGULAR_MIN + ad * 2, RADIAL_MAX)
示例#12
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)
示例#13
0
 def appendScatterSeries(self, name):
     ls = QScatterSeries()
     ls.setName(name)
     self.series.append(ls)
     return ls
示例#14
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()