コード例 #1
0
ファイル: chart.py プロジェクト: scrum-1/Pyslvs-PyQt5
 def __init__(self, Title, mechanism_data=[], parent=None):
     super(ChartDialog, self).__init__(parent)
     self.setWindowTitle("Chart")
     self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint)
     self.setSizeGripEnabled(True)
     self.setModal(True)
     self.setMinimumSize(QSize(800, 600))
     self.Title = Title
     self.mechanism_data = mechanism_data
     #Widgets
     main_layout = QVBoxLayout(self)
     main_layout.setContentsMargins(6, 6, 6, 6)
     self.tabWidget = QTabWidget(self)
     self.setChart("Fitness / Generation Chart", 0, 1)
     self.setChart("Generation / Time Chart", 2, 0)
     self.setChart("Fitness / Time Chart", 2, 1)
     main_layout.addWidget(self.tabWidget)
コード例 #2
0
    def __init__(self, title, algorithm_data, parent: QWidget):
        """Add three tabs of chart."""
        super(ChartDialog, self).__init__(parent)
        self.setWindowTitle("Chart")
        self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint)
        self.setSizeGripEnabled(True)
        self.setModal(True)
        self.setMinimumSize(QSize(800, 600))

        self.__title = title
        self.__algorithm_data = algorithm_data

        # Widgets
        main_layout = QVBoxLayout(self)
        main_layout.setContentsMargins(6, 6, 6, 6)
        self.tabWidget = QTabWidget(self)
        self.__set_chart("Fitness / Generation Chart", 0, 1)
        self.__set_chart("Generation / Time Chart", 2, 0)
        self.__set_chart("Fitness / Time Chart", 2, 1)
        main_layout.addWidget(self.tabWidget)
コード例 #3
0
    def __set_chart(self, tab_name: str, pos_x: int, pos_y: int):
        """Setting charts by data index.

        pos_x / pos_y: [0], [1], [2]
        time_fitness: List[List[Tuple[gen, fitness, time]]]
        """
        axis_x = QCategoryAxis()
        axis_y = QValueAxis()
        axis_x.setLabelsPosition(QCategoryAxis.AxisLabelsPositionOnValue)
        axis_x.setMin(0)
        axis_y.setTickCount(11)

        if self.__algorithm_data:
            # Just copy references from algorithm data.
            plot = [data['time_fitness'] for data in self.__algorithm_data]

            # X max.
            max_x = int(max([max([tnf[pos_x] for tnf in data]) for data in plot]) * 100)
            axis_x.setMax(max_x)
            i10 = int(max_x / 10)
            if i10:
                for i in range(0, max_x + 1, i10):
                    axis_x.append(str(i / 100), i)
            else:
                for i in range(0, 1000, 100):
                    axis_x.append(str(i / 100), i)

            # Y max.
            max_y = max(max([tnf[pos_y] for tnf in data]) for data in plot) + 10
        else:
            plot = None
            # Y max.
            max_y = 100

        max_y -= max_y % 10
        axis_y.setRange(0., max_y)
        chart = DataChart(self.__title, axis_x, axis_y)

        # Append data set.
        for i, data in enumerate(self.__algorithm_data):
            line = QLineSeries()
            scatter = QScatterSeries()
            line.setName(f"{i}: {data['Algorithm']}")
            scatter.setMarkerSize(7)
            scatter.setColor(QColor(110, 190, 30))
            for e in plot[self.__algorithm_data.index(data)]:
                y = e[pos_y]
                x = e[pos_x] * 100
                line.append(QPointF(x, y))
                scatter.append(QPointF(x, y))
            for series in (line, scatter):
                chart.addSeries(series)
                series.attachAxis(axis_x)
                series.attachAxis(axis_y)
            chart.legend().markers(scatter)[0].setVisible(False)

        # Add chart into tab widget
        widget = QWidget()
        self.tabWidget.addTab(widget, QIcon(), tab_name)
        layout = QVBoxLayout(widget)
        layout.setContentsMargins(2, 2, 2, 2)
        chart_view = QChartView(chart)
        chart_view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        layout.addWidget(chart_view)
コード例 #4
0
ファイル: chart.py プロジェクト: scrum-1/Pyslvs-PyQt5
 def setChart(self, tabName: str, posX: int, posY: int):
     '''Setting charts by data index.
     
     posX / posY: [0] / [1] / [2]
     TimeAndFitness: List[List[Tuple[gen, fitness, time]]]
     '''
     if self.mechanism_data:
         if type(self.mechanism_data[0]['TimeAndFitness'][0]) == float:
             TimeAndFitness = [[
                 (data['lastGen'] * i / len(data['TimeAndFitness']), Tnf, 0)
                 for i, Tnf in enumerate(data['TimeAndFitness'])
             ] for data in self.mechanism_data]
         else:
             #Just copy from mechanism_data
             TimeAndFitness = [[Tnf for Tnf in data['TimeAndFitness']]
                               for data in self.mechanism_data]
     axisX = QCategoryAxis()
     axisY = QValueAxis()
     axisX.setLabelsPosition(QCategoryAxis.AxisLabelsPositionOnValue)
     axisX.setMin(0)
     axisY.setTickCount(11)
     #X maxima
     if self.mechanism_data:
         maximaX = int(
             max([
                 max([Tnf[posX] for Tnf in data]) for data in TimeAndFitness
             ]) * 100)
         axisX.setMax(maximaX)
         i10 = int(maximaX / 10)
         if i10:
             for i in range(0, maximaX + 1, i10):
                 axisX.append(str(i / 100), i)
         else:
             for i in range(0, 1000, 100):
                 axisX.append(str(i / 100), i)
     #Y maxima
     if self.mechanism_data:
         maximaY = max(
             [max([Tnf[posY] for Tnf in data])
              for data in TimeAndFitness]) + 10
     else:
         maximaY = 100
     maximaY -= maximaY % 10
     axisY.setRange(0., maximaY)
     chart = DataChart(self.Title, axisX, axisY)
     #Append datasets
     for data in self.mechanism_data:
         line = QLineSeries()
         scatter = QScatterSeries()
         gen = data['lastGen']
         Tnf = TimeAndFitness[self.mechanism_data.index(data)]
         points = Tnf[:-1] if Tnf[-1] == Tnf[-2] else Tnf
         line.setName("{}({} gen): {}".format(data['Algorithm'], gen,
                                              data['Expression']))
         scatter.setMarkerSize(7)
         scatter.setColor(QColor(110, 190, 30))
         for i, e in enumerate(points):
             y = e[posY]
             x = e[posX] * 100
             line.append(QPointF(x, y))
             scatter.append(QPointF(x, y))
         for series in [line, scatter]:
             chart.addSeries(series)
             series.attachAxis(axisX)
             series.attachAxis(axisY)
         chart.legend().markers(scatter)[0].setVisible(False)
     #Add chart into tab widget
     widget = QWidget()
     self.tabWidget.addTab(widget, QIcon(), tabName)
     layout = QVBoxLayout(widget)
     layout.setContentsMargins(2, 2, 2, 2)
     chartView = QChartView(chart)
     chartView.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
     layout.addWidget(chartView)