def __init__(self, title: str, axis: list) -> None: chart = QtCharts.QChart() chart.setTitle(title) chart.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) chart.setMinimumHeight(560) chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations) chart.setAnimationDuration(500) chart.setAnimationEasingCurve(QEasingCurve.OutCubic) super().__init__(chart) self.xa = QtCharts.QBarCategoryAxis() self.xa.append(axis) self.setVisible(False)
def refresh(self, B, M): sets = [QtCharts.QBarSet(i) for i in self.axis] for s, b, m in zip(sets, B, M): s.append([b, m]) s.setLabelColor(QColor('black')) series = QtCharts.QBarSeries() series.setLabelsVisible(True) series.setLabelsPosition(QtCharts.QAbstractBarSeries.LabelsOutsideEnd) series.append(sets) self.chart().removeAllSeries() self.chart().addSeries(series) self.chart().setAxisX(self.xa, series) self.chart().setAxisY(self.ya, series) self.ya.setRange(0, max(B + M)) self.setVisible(True)
def refresh(self, p, r): pre = QtCharts.QBarSet('precision') rec = QtCharts.QBarSet('recall') pre.append(p) rec.append(r) pre.setLabelColor(QColor('#000000')) rec.setLabelColor(QColor('#000000')) series = QtCharts.QBarSeries() series.setLabelsVisible(True) series.setLabelsPosition(QtCharts.QAbstractBarSeries.LabelsOutsideEnd) series.setLabelsPrecision(4) series.append(pre) series.append(rec) self.chart().removeAllSeries() self.chart().addSeries(series) self.chart().setAxisX(self.xa, series) self.chart().setAxisY(self.ya, series) self.setVisible(True)
def refresh(self, cm: torch.LongTensor): K = len(cm) color = [QColor(j) for j in COLOR[:K]] self.chart().removeAllSeries() for i in range(K): series = QtCharts.QPieSeries() series.setName(f'{i}') series.setHorizontalPosition((i + 0.5) / K) series.setPieSize(1 / K) for j in range(K): if (v := cm[i, j]): series.append(f"pred as {BIRAD_MAP[j]}", v) series.slices()[-1].setColor(color[j]) series.setLabelsVisible(True) self.chart().addSeries(series) self.chart().setAxisX(self.xa, series)
def __set_chart(self, tab_name: str, pos_x: int, pos_y: int) -> None: """Setting charts by data index. pos_x / pos_y: [0], [1], [2] time_fitness: List[List[Tuple[gen, fitness, time]]] """ axis_x = QtCharts.QCategoryAxis() axis_y = QtCharts.QValueAxis() axis_x.setLabelsPosition( QtCharts.QCategoryAxis.AxisLabelsPositionOnValue) axis_x.setMin(0) axis_y.setTickCount(11) if self.algorithm_data: # Just copy references from algorithm data plot: _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 = [] # 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 = QtCharts.QLineSeries() scatter = QtCharts.QScatterSeries() line.setName(f"{i}: {data['Algorithm']}") scatter.setMarkerSize(7) scatter.setColor(QColor(110, 190, 30)) if plot: 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 = QtCharts.QChartView(chart) chart_view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) layout.addWidget(chart_view)
def __init__(self, title: str, axis: list) -> None: super().__init__(title, ['benign', 'malignant']) self.axis = axis self.ya = QtCharts.QValueAxis()
def __init__(self, title: str, axis: list) -> None: super().__init__(title, axis) self.ya = QtCharts.QValueAxis() self.ya.setRange(0, 1)