def __init__(self): super().__init__() self.resize(800, 600) set0 = QBarSet('X0') set1 = QBarSet('X1') set2 = QBarSet('X2') set3 = QBarSet('X3') set4 = QBarSet('X4') set0.append([1, 2, 3, 4, 5, 6]) set1.append([5, 0, 0, 4, 0, 7]) set2.append([3, 5, 8, 13, 8, 5]) set3.append([5, 6, 7, 3, 4, 5]) set4.append([9, 7, 5, 3, 1, 2]) series = QHorizontalBarSeries() series.append(set0) series.append(set1) series.append(set2) series.append(set3) series.append(set4) chart = QChart() chart.addSeries(series) chart.setTitle('Horizontal Bar Chart Demo') chart.setAnimationOptions(QChart.SeriesAnimations) months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June') axisY = QBarCategoryAxis() axisY.append(months) chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) axisX = QValueAxis() chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisX.applyNiceNumbers() chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(chartView)
def create_graph(self): self.emotion_set = QBarSet('Confidence Level') self.emotion_set.append([ self.face_anger_digust, self.face_happy, self.face_neutral, self.face_sadness, self.face_surprise_fear ]) series = QHorizontalBarSeries() series.append(self.emotion_set) chart = QChart() chart.addSeries(series) chart.setTitle('ReLuu FaceReader') chart.setAnimationOptions(QChart.SeriesAnimations) months = ('Angery and Disgusted', 'Happy', 'Neutral', 'Sadness', 'Fear and Surprise') axisY = QBarCategoryAxis() axisY.append(months) chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) axisX = QValueAxis() axisX.setMax(1.0) chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisX.applyNiceNumbers() chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) self.setCentralWidget(chartView)
def run_statistics(self): text = self.comp_type_crt_text x_vals = [] y_vals = [] if text[:5] == "Inter": data_sets = [] for check_box in self.check_boxes: if check_box.isChecked(): data_sets.append(self.check_boxes[check_box]) metric = self.select_metric_inter.currentText() metric_alias = self.dict_metric_inter[metric] res = ResultsManager.get_results_inter(metric_alias, data_sets) # self.graphWidget.plot(data_sets, res) x_vals = data_sets y_vals = res elif text[:5] == "Intra": ds_name = self.intra_ds_current metric = self.select_metric_intra.currentText() metric_alias = self.dict_metric_intra[metric] names, res = ResultsManager.get_results_intra(metric_alias, ds_name) # self.graphWidget.plot(names, res) x_vals = names y_vals = res #horizontal bar chart_view = None if self.select_chart.currentIndex() == 0: chart = QChart(flags=Qt.WindowFlags()) series = QHorizontalBarSeries() for i in range(len(x_vals)): name = x_vals[i] set0 = QBarSet(name) set0.append(y_vals[i]) series.append(set0) chart.addSeries(series) if text[:5] == "Inter": chart.setTitle(f"Comparison by {self.select_metric_inter.currentText()}") else: chart.setTitle(f"Comparison by {self.select_metric_intra.currentText()}") chart.setAnimationOptions(QChart.SeriesAnimations) chart_view = QChartView(chart) self.graph_layout.replaceWidget(self.crt_chart, chart_view) self.crt_chart = chart_view axisX = QValueAxis() chart.addAxis(axisX, Qt.AlignBottom) series.attachAxis(axisX) axisX.applyNiceNumbers() chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chart_view.setRenderHint(QPainter.Antialiasing) chart_view.setBackgroundBrush(QColor(0, 0, 0, 255)) chart.setBackgroundBrush(QColor(255, 255, 0, 255)) # vertical bar elif self.select_chart.currentIndex() == 1: chart = QChart(flags=Qt.WindowFlags()) series = QBarSeries() for i in range(len(x_vals)): name = x_vals[i] set0 = QBarSet(name) set0.append(y_vals[i]) series.append(set0) chart.addSeries(series) if text[:5] == "Inter": chart.setTitle(f"Comparison by {self.select_metric_inter.currentText()}") else: chart.setTitle(f"Comparison by {self.select_metric_intra.currentText()}") chart.setAnimationOptions(QChart.SeriesAnimations) chart_view = QChartView(chart) self.graph_layout.replaceWidget(self.crt_chart, chart_view) self.crt_chart = chart_view axisY = QValueAxis() chart.addAxis(axisY, Qt.AlignLeft) series.attachAxis(axisY) axisY.applyNiceNumbers() chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chart_view.setRenderHint(QPainter.Antialiasing) chart_view.setBackgroundBrush(QColor(0, 0, 0, 255)) chart.setBackgroundBrush(QColor(255, 255, 0, 255)) # pie chart elif self.select_chart.currentIndex() == 2: chart = QChart(flags=Qt.WindowFlags()) series = QPieSeries() for i in range(len(x_vals)): series.append(x_vals[i], y_vals[i]) chart.addSeries(series) if text[:5] == "Inter": chart.setTitle(f"Comparison by {self.select_metric_inter.currentText()}") else: chart.setTitle(f"Comparison by {self.select_metric_intra.currentText()}") chart.setAnimationOptions(QChart.SeriesAnimations) chart.legend().setAlignment(Qt.AlignBottom) # chart.legend().setFont(QFont("Arial", 12)) chart_view = QChartView(chart) self.graph_layout.replaceWidget(self.crt_chart, chart_view) self.crt_chart = chart_view chart_view.setRenderHint(QPainter.Antialiasing) chart_view.setBackgroundBrush(QColor(0, 0, 0, 255)) chart.setBackgroundBrush(QColor(255, 255, 0, 255)) chart_view.setRubberBand(QChartView.HorizontalRubberBand) chart_view.setRubberBand(QChartView.VerticalRubberBand)