Ejemplo n.º 1
0
    def generate_barSet(self):

        self.vmafbs_dict = {}
        self.psnrbs_dict = {}
        self.bitratebs_dict = {}

        self.vmaf_barSeries = QtCharts.QBarSeries()
        self.psnr_barSeries = QtCharts.QBarSeries()
        self.bitrate_barSeries = QtCharts.QBarSeries()

        for obj in self.list_obj:

            try:
                self.vmafbs_dict[obj.filename] = QtCharts.QBarSet(obj.filename)
                self.vmafbs_dict[obj.filename].append([obj.vmaf_avg])
            except:
                pass

            try:
                self.psnrbs_dict[obj.filename] = QtCharts.QBarSet(obj.filename)
                self.psnrbs_dict[obj.filename].append([obj.psnr_avg])
            except:
                pass

            try:
                self.bitratebs_dict[obj.filename] = QtCharts.QBarSet(
                    obj.filename)
                self.bitratebs_dict[obj.filename].append([obj.bitrate_avg])
            except:
                pass
Ejemplo n.º 2
0
    def createBarCharts(self, x, y1, y2):
        barSet1 = QtCharts.QBarSet("Magnitude")
        # c1 = PySide2.QtWidgets.QColorDialog.getColor()
        barSet1.setColor(Qt.white)
        barSet1.append(y1)

        barSet2 = QtCharts.QBarSet("Depths")
        barSet2.setColor(Qt.magenta)
        barSet2.append(y2)

        barSeries1 = QtCharts.QBarSeries()
        barSeries1.append(barSet1)
        barSeries1.append(barSet2)

        barChart1 = QtCharts.QChart()
        barChart1.addSeries(barSeries1)
        barChart1.setTitle("my first bar chart")
        barChart1.setAnimationOptions(QtCharts.QChart.SeriesAnimations)

        categories = x
        barCategoryAxis = QtCharts.QBarCategoryAxis()
        barCategoryAxis.append(categories)
        barChart1.createDefaultAxes()
        barChart1.setAxisX(barCategoryAxis, barSeries1)

        barChart1.legend().setVisible(True)
        barChart1.legend().setAlignment(Qt.AlignTop)

        return barChart1
Ejemplo n.º 3
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        bar_set = QtCharts.QBarSet("ME")
        bar_set.setColor(QColor(231, 119, 32))
        self.task_list = None
        self.setFont("Roboto Light")

        self.max_bound: datetime = datetime.datetime.now()

        self.setFixedSize(651, 421)
        self.interval = 7

        self.series = QtCharts.QBarSeries()
        self.chart = QtCharts.QChart()
        self.chart.addSeries(self.series)
        self.chart.setFont("Roboto Light")
        self.chart.setTitle("Task Done")
        self.chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)

        self.axisX = QtCharts.QBarCategoryAxis()
        self.axisY = QtCharts.QValueAxis()

        self.chart.setAxisY(self.axisY, self.series)
        self.chart.setAxisX(self.axisX, self.series)
        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(Qt.AlignBottom)

        self.chartView = QtCharts.QChartView(self.chart)
        self.chartView.setRenderHint(QPainter.Antialiasing)

        self.main_layout = QVBoxLayout(self)
        self.main_layout.addWidget(self.chartView)
        self.setLayout(self.main_layout)
Ejemplo n.º 4
0
    def _set_returns_chart(self,
                           asset_universe: List[str],
                           implied_returns: pd.Series) -> None:

        implied_returns = implied_returns.reindex(asset_universe)
        bar_series = QtCharts.QBarSeries()
        bar_set = QtCharts.QBarSet("Returns")
        bar_set.append(implied_returns.mul(100).values.tolist())
        bar_series.append(bar_set)

        # configure basic chart
        chart = QtCharts.QChart()
        chart.setTitle("Market Implied Expected Returns")
        title_font = QtGui.QFont()
        title_font.setBold(True)
        chart.setFont(title_font)
        chart.addSeries(bar_series)

        # configure the x axis
        axis_x = QtCharts.QBarCategoryAxis()
        axis_x.append([s.replace(" ", "<br>") for s in asset_universe])
        chart.createDefaultAxes()
        chart.setAxisX(axis_x)

        # configure the y axis
        y_min = implied_returns.min() * 100
        y_max = implied_returns.max() * 100
        axis_y = QtCharts.QValueAxis()
        self._set_y_axis_limits(y_max, y_min, axis_y, 2)
        axis_y.setLabelFormat("%.0f")
        axis_y.setTitleText("Expected Return (%pa)")
        chart.setAxisY(axis_y)
        bar_series.attachAxis(axis_y)

        self._returns_chart_view.setChart(chart)
Ejemplo n.º 5
0
    def __init__(self, title: str = None, parent: QtWidgets.QWidget = None):
        super().__init__(QtCharts.QChart(), theme=light_theme, parent=parent)
        self.setMinimumSize(QtCore.QSize(640, 320))
        self.setRenderHint(QtGui.QPainter.Antialiasing)

        if title is not None:
            self.chart().setTitle(title)

        self.chart().legend().hide()

        self._xaxis = QtCharts.QValueAxis()  # Alignment axis
        self._xaxis.setVisible(False)
        self.xaxis = QtCharts.QValueAxis()  # Value axis
        self.xaxis.setGridLineVisible(False)

        self.yaxis = QtCharts.QValueAxis()
        self.yaxis.setGridLineVisible(False)
        self.yaxis.setLabelFormat("%d")

        self.addAxis(self._xaxis, QtCore.Qt.AlignBottom)
        self.addAxis(self.xaxis, QtCore.Qt.AlignBottom)
        self.addAxis(self.yaxis, QtCore.Qt.AlignLeft)

        self.series = QtCharts.QBarSeries()
        self.series.setBarWidth(1.0)

        self.chart().addSeries(self.series)
        self.series.attachAxis(self._xaxis)
        self.series.attachAxis(self.yaxis)
Ejemplo n.º 6
0
    def plotSavingsBars(self):
        chart = QtCharts.QChart()

        # barSets = []
        maxVal = 0
        minVal = 0
        barSeries = QtCharts.QBarSeries()
        expSet = QtCharts.QBarSet('Ausgaben')
        expSet.append(self.sumData['exp'])
        maxVal = max(maxVal, max(self.sumData['exp']))
        minVal = min(minVal, min(self.sumData['exp']))
        barSeries.append(expSet)

        incSet = QtCharts.QBarSet('Einnahmen')
        incSet.append(self.sumData['inc'])
        maxVal = max(maxVal, max(self.sumData['inc']))
        minVal = min(minVal, min(self.sumData['inc']))
        barSeries.append(incSet)

        savSet = QtCharts.QBarSet('Rücklagen')
        savSet.append(self.sumData['sav'])
        maxVal = max(maxVal, max(self.sumData['sav']))
        minVal = min(minVal, min(self.sumData['sav']))
        barSeries.append(savSet)

        # self.barSets = barSets

        chart.addSeries(barSeries)
        titleFont = QFont("Sans Serif")
        titleFont.setPointSize(16)
        titleFont.setBold(True)

        chart.setTitleFont(titleFont)
        chart.setTitle("Rücklagen")

        axisX = QtCharts.QBarCategoryAxis()
        axisX.append(self.plotDataTags)
        chart.setAxisX(axisX, barSeries)
        # axisX.setRange(self.plotDataTags[0], self.plotDataTags[-1])

        axisY = QtCharts.QValueAxis()
        axisY.setLabelFormat("%i")
        axisY.setTitleText("€")
        if minVal < 0:
            self.setYRange(maxVal, axisY, minVal)
        else:
            self.setYRange(maxVal, axisY)
        # chart.setAxisY(axisY, lineSeries)
        chart.setAxisY(axisY, barSeries)
        # axisY.setRange(0, 20)

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignRight)

        self.setChart(chart)
        self.setRenderHint(QPainter.Antialiasing)
        # draw the plot from scratch (if that makes a difference)
        print('Savings bar plot drawn')
Ejemplo n.º 7
0
 def setBarChartData(self, data: List[int]):
     barSet = QtCharts.QBarSet("Days")
     barSet.append(data)
     series = QtCharts.QBarSeries()
     series.append(barSet)
     chartBar = QtCharts.QChart()
     chartBar.addSeries(series)
     chartBar.setTitle("Reviews by days")
     chartBar.setAnimationOptions(QtCharts.QChart.SeriesAnimations)
     self.chartBarView.setChart(chartBar)
Ejemplo n.º 8
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.set0 = QtCharts.QBarSet("Jane")
        self.set1 = QtCharts.QBarSet("John")
        self.set2 = QtCharts.QBarSet("Axel")
        self.set3 = QtCharts.QBarSet("Mary")
        self.set4 = QtCharts.QBarSet("Sam")

        self.set0.append([1, 2, 3, 4, 5, 6])
        self.set1.append([5, 0, 0, 4, 0, 7])
        self.set2.append([3, 5, 8, 13, 8, 5])
        self.set3.append([5, 6, 7, 3, 4, 5])
        self.set4.append([9, 7, 5, 3, 1, 2])

        self.barSeries = QtCharts.QBarSeries()
        self.barSeries.append(self.set0)
        self.barSeries.append(self.set1)
        self.barSeries.append(self.set2)
        self.barSeries.append(self.set3)
        self.barSeries.append(self.set4)

        self.lineSeries = QtCharts.QLineSeries()
        self.lineSeries.setName("trend")
        self.lineSeries.append(QPoint(0, 4))
        self.lineSeries.append(QPoint(1, 15))
        self.lineSeries.append(QPoint(2, 20))
        self.lineSeries.append(QPoint(3, 4))
        self.lineSeries.append(QPoint(4, 12))
        self.lineSeries.append(QPoint(5, 17))

        self.chart = QtCharts.QChart()
        self.chart.addSeries(self.barSeries)
        self.chart.addSeries(self.lineSeries)
        self.chart.setTitle("Line and barchart example")

        self.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
        self.axisX = QtCharts.QBarCategoryAxis()
        self.axisX.append(self.categories)
        self.chart.setAxisX(self.axisX, self.lineSeries)
        self.chart.setAxisX(self.axisX, self.barSeries)
        self.axisX.setRange("Jan", "Jun")

        self.axisY = QtCharts.QValueAxis()
        self.chart.setAxisY(self.axisY, self.lineSeries)
        self.chart.setAxisY(self.axisY, self.barSeries)
        self.axisY.setRange(0, 20)

        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(Qt.AlignBottom)

        self.chartView = QtCharts.QChartView(self.chart)
        self.chartView.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(self.chartView)
    def __init__(self, dayIndex, timeIndex, areaIndex):
        super(userDataVisual, self).__init__()
        self.setupUi(self)
        self.bg_pixmap = QPixmap(u":/bg.jpg")
        self.org_bg_pixmap = QPixmap(u":/bg.jpg")

        self.__dayIndex = dayIndex
        self.__timeIndex = timeIndex
        self.__areaIndex = areaIndex

        start_time, end_time = self.getTimeRange()
        month_time, day_time = self.getDay()
        analyser = DataAnalysis(start_time, end_time, month_time, day_time,
                                self.__areaIndex)

        self.average_temperature.setText("平均温度:{}".format(
            round(analyser.average_temperature, 2)))
        self.people_count.setText("总人数:{}".format(analyser.people_count))
        self.area_risk.setText(
            "该地区风险:{}".format("低" if analyser.area_risk_level == 0 else "高"))

        categories_count = analyser.get_people_count_by_temperature_range(
            35, 38.5, 0.5)
        self.set0 = QtCharts.QBarSet("temp-count")
        self.set0.append(categories_count)
        self.barSeries = QtCharts.QBarSeries()
        self.barSeries.append(self.set0)

        self.chart = QtCharts.QChart()
        self.chart.addSeries(self.barSeries)
        self.chart.setTitle("区域时段统计图")

        self.categories = ["35以下"]
        self.categories.extend(
            [str(i * 0.5 + 35) for i in range(len(categories_count) - 2)])
        self.categories.extend(["38.5以上"])
        self.axisX = QtCharts.QBarCategoryAxis()
        self.axisX.append(self.categories)
        self.chart.setAxisX(self.axisX, self.barSeries)
        self.axisX.setRange("35以下", "38.5以上")

        self.axisY = QtCharts.QValueAxis()
        self.chart.setAxisY(self.axisY, self.barSeries)
        self.axisY.setRange(min(categories_count), max(categories_count))

        self.chart.axisY().setTitleText("人数")
        self.chart.axisX().setTitleText("体温")
        self.chart.legend().setVisible(False)
        self.chart.legend().setAlignment(Qt.AlignBottom)

        self.chartView = QtCharts.QChartView(self.chart, self.centralwidget)
        self.chartView.setRenderHint(QPainter.Antialiasing)
        self.chartView.setGeometry(QRect(50, 50, 600, 450))
Ejemplo n.º 10
0
    def __init__(self):
        super(Teacher_OP, self).__init__()
        self.setupUi(self)
        self.time = 0
        self.num = 0  # 记录上张表的标签数量

        self.get_time_timer = QTimer(self)

        self.get_table_list_thread = Table_List_Get(self)

        self.count_timer = QTimer(self)

        self.clear_msg_timer = QTimer(self)

        self.list_model = QStringListModel()
        self.table_list.setModel(self.list_model)

        self.get_table_data_thread = Table_Data_Get(self)

        self.start_sign_thread = Start_Sign_IN(self)

        self.stop_sign_thread = Stop_Sign_IN(self)

        self.get_time_thread = Get_Time(self)

        self.delete_table_thread = Delete_Option(self)

        self.train_model_thread = Train_Model(self)

        self.creat_excel_thread = Creat_Excel(self)

        # chart
        self.series = QtCharts.QBarSeries(self)
        self.target_bar = QtCharts.QBarSet('学生数量')
        self.series.append(self.target_bar)

        self.axis_x = QtCharts.QBarCategoryAxis()
        self.axis_x.setLabelsColor(QColor(255, 0, 0))

        self.axis_y = QtCharts.QValueAxis()
        # self.axis_y.setTitleText('人数')

        self.chart = QtCharts.QChart()
        self.chart.addSeries(self.series)
        self.chart.setAxisX(self.axis_x, self.series)
        self.chart.setAxisY(self.axis_y, self.series)

        self.qcv = QtCharts.QChartView(self.chart)

        self.init_connect()
        self.set_start_dis_and_set_stop_en(False)
Ejemplo n.º 11
0
    def __init__(self, parent: QtWidgets.QGraphicsItem = None):
        super().__init__(parent)
        self.setMinimumSize(640, 320)

        self._xaxis = QtCharts.QValueAxis()
        self._xaxis.setVisible(False)

        self.xaxis = NiceValueAxis()
        self.xaxis.setTitleText("Size (nm)")
        self.xaxis.setGridLineVisible(False)

        self.yaxis = QtCharts.QValueAxis()
        self.yaxis.setGridLineVisible(False)
        self.yaxis.setTitleText("Count")
        self.yaxis.setLabelFormat("%d")

        self.addAxis(self._xaxis, QtCore.Qt.AlignBottom)
        self.addAxis(self.xaxis, QtCore.Qt.AlignBottom)
        self.addAxis(self.yaxis, QtCore.Qt.AlignLeft)

        self.series = QtCharts.QBarSeries()
        self.series.setBarWidth(0.9)
        self.addSeries(self.series)
        self.series.attachAxis(self._xaxis)
        self.series.attachAxis(self.yaxis)

        self.set = QtCharts.QBarSet("sizes")
        self.set.setColor(QtCore.Qt.black)
        self.set.hovered.connect(self.barHovered)
        self.series.append(self.set)

        self.fit = QtCharts.QSplineSeries()
        self.fit.setPen(QtGui.QPen(QtGui.QColor(255, 172, 0), 2.0))
        self.addSeries(self.fit)
        self.fit.attachAxis(self.xaxis)
        self.fit.attachAxis(self.yaxis)

        self.label_fit = QtWidgets.QGraphicsTextItem(self)
        self.label_fit.setFont(QtGui.QFont("sans", 12, italic=False))
        self.label_fit.setZValue(99)
        self.label_fit.setDefaultTextColor(QtGui.QColor(255, 172, 0))
        self.xaxis.rangeChanged.connect(self.updateFitLabelPos)

        self.label_hovered = QtWidgets.QGraphicsTextItem(self)
        self.plotAreaChanged.connect(self.updateHoveredLabelPos)

        self.vlines: List[QtCharts.QLineSeries] = []

        # Clean legend
        self.legend().setMarkerShape(QtCharts.QLegend.MarkerShapeFromSeries)
        self.legend().markers(self.series)[0].setVisible(False)
Ejemplo n.º 12
0
    def creador_barseries(self, listaelementos, rotacion=0, formato="@value"):

        barraseries = QtCharts.QBarSeries()
        for item in listaelementos:  # agrega los datos
            barraseries.append(item)
        barraseries.setLabelsVisible(True)
        barraseries.setLabelsFormat(formato)
        barraseries.setLabelsAngle(rotacion)

        # Posicionamiento del "label" valor /-/-/-/
        'LabelsCenter | LabelsOutsideEnd | LabelsInsideEnd | LabelsInsideBase'
        barraseries.setLabelsPosition(
            QtCharts.QAbstractBarSeries.LabelsOutsideEnd)

        return barraseries
Ejemplo n.º 13
0
    def plot_data(self):
        # Get table information
        series = QtCharts.QBarSeries()
        for i in range(self.table.rowCount()):
            text = self.table.item(i, 0).text()
            number = float(self.table.item(i, 1).text())

            bar_set = QtCharts.QBarSet(text)
            bar_set.append(number)

            series.append(bar_set)

        chart = QtCharts.QChart()
        chart.addSeries(series)
        chart.legend().setAlignment(Qt.AlignLeft)
        self.chart_view.setChart(chart)
Ejemplo n.º 14
0
    def setData(self, data: Dict[Any, int], asRanges: bool = False):
        self.clearChart()
        if not data:
            return
        barSet = QtCharts.QBarSet('Frequency')
        frequencies = [f for f in data.values()]
        self.currentBinN = len(frequencies)
        barSet.append(frequencies)
        series = QtCharts.QBarSeries()
        series.append(barSet)
        chart = QtCharts.QChart()
        chart.addSeries(series)
        chart.setTitle('Value frequency ({} bins)'.format(self.currentBinN))
        chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)

        labels = ['{:.2f}'.format(k) if isinstance(k, float) else str(k) for k in data.keys()]
        if asRanges:
            if isFloat(labels[0]):
                # Assume labels are float
                if len(labels) > 1:
                    # If there is one or less labels stop
                    lastEnd = float(labels[-1]) + (float(labels[1]) - float(labels[0]))
                    labels.append('{:.2f}'.format(lastEnd))
            axisX = QtCharts.QCategoryAxis()
            for i in range(len(labels) - 1):
                axisX.append(labels[i + 1], (i + 1) * 2 * series.barWidth())
            axisX.setStartValue(0)
            axisX.setLabelsPosition(QtCharts.QCategoryAxis.AxisLabelsPositionCenter)
        else:
            axisX = QtCharts.QBarCategoryAxis()
            axisX.append(labels)
        # Set font
        font: QFont = axisX.labelsFont()
        font.setPointSize(11)
        axisX.setLabelsFont(font)
        chart.addAxis(axisX, Qt.AlignBottom)
        series.attachAxis(axisX)

        axisY = QtCharts.QValueAxis()
        axisY.setRange(0, max(frequencies) + 1)
        axisY.setLabelFormat('%d')
        chart.addAxis(axisY, Qt.AlignLeft)
        series.attachAxis(axisY)
        chart.legend().setVisible(False)

        self.chart = chart
        self.chartView.setChart(self.chart)
Ejemplo n.º 15
0
    def _set_weights_chart(self,
                           asset_universe: List[str],
                           *args: pd.Series) -> None:

        bar_series = QtCharts.QBarSeries()
        y_min = 0
        y_max = 0

        for weights in args:

            weights = weights.reindex(asset_universe)
            y_min = min(weights.min() * 100, y_min)
            y_max = max(weights.max() * 100, y_max)

            bar_set = QtCharts.QBarSet(str(weights.name))
            bar_set.append(weights.mul(100).values.tolist())
            bar_series.append(bar_set)

        # configure basic chart
        chart = QtCharts.QChart()
        chart.setTitle("Black-Litterman Asset Allocation")
        title_font = QtGui.QFont()
        title_font.setBold(True)
        chart.setFont(title_font)
        chart.addSeries(bar_series)

        # configure the x axis
        axis_x = QtCharts.QBarCategoryAxis()
        axis_x.append([s.replace(" ", "<br>") for s in asset_universe])
        chart.createDefaultAxes()
        chart.setAxisX(axis_x)

        # configure the y axis
        axis_y = QtCharts.QValueAxis()
        self._set_y_axis_limits(y_max, y_min, axis_y)
        axis_y.setLabelFormat("%.0f")
        axis_y.setTitleText("Suggested Allocation (%)")
        chart.setAxisY(axis_y)
        bar_series.attachAxis(axis_y)

        # configure chart legend
        chart.legend().setVisible(True)
        chart.legend().setAlignment(QtCore.Qt.AlignBottom)

        self._weights_chart_view.setChart(chart)
Ejemplo n.º 16
0
 def plot_data(self):
     presence = QtCharts.QBarSet('現在')
     goal = QtCharts.QBarSet('目標')
     presence.append([self.total_calorie/self.goal_calorie,self.total_protein/self.goal_protein,\
         self.total_fat/self.goal_fat,self.total_carbon/self.goal_carbon])
     goal.append([1,1,1,1])
     series = QtCharts.QBarSeries()
     series.append(presence); series.append(goal)
     chart = QtCharts.QChart()
     chart.addSeries(series)
     chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)
     labels = ['カロリー','たんぱく質','脂質','炭水化物']
     axisX = QtCharts.QBarCategoryAxis()
     axisX.append(labels)
     chart.addAxis(axisX,Qt.AlignBottom)
     chart.legend().setVisible(True)
     chart.legend().setFont(QtGui.QFont('Arial',10,QtGui.QFont.Bold))
     chart.setTheme(QtCharts.QChart.ChartThemeHighContrast)
     self.chartview.setChart(chart)
Ejemplo n.º 17
0
    def Create_Bar_Graph(self, data_df, name):

        self.graph_4 = QtCharts.QChartView()
        self.graph_4.series = QtCharts.QBarSeries()
        """
        self.graph_4 = QtCharts.QChartView(self.frame_4)
        self.graph_4.series = QtCharts.QBarSeries(self.frame_4)
        """
        for column in data_df.columns:
            bar_set = QtCharts.QBarSet(column)
            bar_set.append(list(data_df[column].values))
            self.graph_4.series.append(bar_set)
        self.graph_4.chart().setTitle("Device Summary")
        self.graph_4.chart().addSeries(self.graph_4.series)

        #self.graph_4.setGeometry(0, 0, self.frame_4.width(), self.frame_4.height())
        axis = QtCharts.QBarCategoryAxis()
        axis.append(["Pixels"])
        self.graph_4.chart().createDefaultAxes()
        self.graph_4.chart().addAxis(axis, QtCore.Qt.AlignBottom)
        self.frame_layout.addWidget(self.graph_4)
        self.Resize()
Ejemplo n.º 18
0
    def add_bar_series(self, res_dict):
        self.barset = QtCharts.QBarSet('Watson')
        cats = []
        for item in res_dict:
            self.barset.append(res_dict[item])
            cats.append(item)

        self.series = QtCharts.QBarSeries()
        self.series.append(self.barset)
        self.chart.addSeries(self.series)

        # Setting X-axis
        self.axis_x = QtCharts.QBarCategoryAxis()
        cat = ('sadness', 'joy', 'fear', 'disgust', 'anger')
        self.axis_x.append(cat)
        self.chart.addAxis(self.axis_x, Qt.AlignBottom)
        self.series.attachAxis(self.axis_x)

        # Setting Y-axis
        self.axis_y = QtCharts.QValueAxis()
        # self.axis_y.setTitleText("Percentage")
        self.chart.addAxis(self.axis_y, Qt.AlignLeft)
        self.series.attachAxis(self.axis_y)
Ejemplo n.º 19
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setWindowTitle('MNIST Image Classification Test')

        self.canvas = Canvas()
        size_policy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.MinimumExpanding)
        size_policy.setHeightForWidth(True)
        self.canvas.setSizePolicy(size_policy)

        self.probabilities = QtCharts.QBarSet('Probability')
        self.probabilities.append([0.1 for _ in range(10)])
        series = QtCharts.QBarSeries()
        series.append(self.probabilities)
        chart = QtCharts.QChart()
        chart.addSeries(series)
        chart_view = QtCharts.QChartView(chart)
        chart_view.setSizePolicy(size_policy)

        x_axis = QtCharts.QBarCategoryAxis()
        x_axis.setCategories([str(i) for i in range(10)])
        chart.addAxis(x_axis, QtCore.Qt.AlignBottom)
        series.attachAxis(x_axis)

        y_axis = QtCharts.QValueAxis()
        y_axis.setRange(0.0, 1.0)
        y_axis.setTickCount(11)
        chart.addAxis(y_axis, QtCore.Qt.AlignLeft)
        series.attachAxis(y_axis)

        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.canvas)
        layout.addWidget(chart_view)

        self.setLayout(layout)
        self.show()
Ejemplo n.º 20
0
def copyChart(chart: QtCharts.QChart) -> QtCharts.QChart:
    """ Return a copy of the chart """
    newChart = QtCharts.QChart()
    # Copy axes
    axes = chart.axes()
    for axis in axes:
        newChart.addAxis(copyAxis(newChart, axis), axis.alignment())
    # Copy series
    allSeries: List[QtCharts.QAbstractSeries] = chart.series()
    for s in allSeries:
        # Create new series with same points, dependent on actual type
        s_copy: QtCharts.QAbstractSeries
        if isinstance(s, QtCharts.QScatterSeries):
            s_copy = QtCharts.QScatterSeries()
            s_copy.append(s.points())
        elif isinstance(s, QtCharts.QLineSeries):
            s_copy = QtCharts.QLineSeries()
            s_copy.append(s.points())
        elif isinstance(s, QtCharts.QAbstractBarSeries):
            # Note: this is not used
            s_copy = QtCharts.QBarSeries()
            for bar in s.barSets():
                bar_copy = QtCharts.QBarSet(bar.label())
                s_copy.append(bar_copy)
        else:
            raise NotImplementedError('Cannot copy series of type {}'.format(
                type(s)))
        s_copy.setName(s.name())
        # Add series to chart
        newChart.addSeries(s_copy)
        # Add axis to series
        s_copy.attachAxis(newChart.axisX())
        s_copy.attachAxis(newChart.axisY())
    if chart.title():
        newChart.setTitle(chart.title())
    return newChart
Ejemplo n.º 21
0
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)
        self.chart = QtCharts.QChart()
        self.series = QtCharts.QBarSeries()

        self.main_layout = QGridLayout()
        self.button_layout = QGridLayout()
        self.font_layout = QFormLayout()

        self.font_size = QDoubleSpinBox()

        self.legend_posx = QDoubleSpinBox()
        self.legend_posy = QDoubleSpinBox()
        self.legend_width = QDoubleSpinBox()
        self.legend_height = QDoubleSpinBox()

        self.detach_legend_button = QPushButton("Toggle attached")
        self.detach_legend_button.clicked.connect(self.toggle_attached)
        self.button_layout.addWidget(self.detach_legend_button, 0, 0)

        self.add_set_button = QPushButton("add barset")
        self.add_set_button.clicked.connect(self.add_barset)
        self.button_layout.addWidget(self.add_set_button, 2, 0)

        self.remove_barset_button = QPushButton("remove barset")
        self.remove_barset_button.clicked.connect(self.remove_barset)
        self.button_layout.addWidget(self.remove_barset_button, 3, 0)

        self.align_button = QPushButton("Align (Bottom)")
        self.align_button.clicked.connect(self.set_legend_alignment)
        self.button_layout.addWidget(self.align_button, 4, 0)

        self.bold_button = QPushButton("Toggle bold")
        self.bold_button.clicked.connect(self.toggle_bold)
        self.button_layout.addWidget(self.bold_button, 8, 0)

        self.italic_button = QPushButton("Toggle italic")
        self.italic_button.clicked.connect(self.toggle_italic)
        self.button_layout.addWidget(self.italic_button, 9, 0)

        self.legend_posx.valueChanged.connect(self.update_legend_layout)
        self.legend_posy.valueChanged.connect(self.update_legend_layout)
        self.legend_width.valueChanged.connect(self.update_legend_layout)
        self.legend_height.valueChanged.connect(self.update_legend_layout)

        legend_layout = QFormLayout()
        legend_layout.addRow("HPos", self.legend_posx)
        legend_layout.addRow("VPos", self.legend_posy)
        legend_layout.addRow("Width", self.legend_width)
        legend_layout.addRow("Height", self.legend_height)

        self.legend_settings = QGroupBox("Detached legend")
        self.legend_settings.setLayout(legend_layout)
        self.button_layout.addWidget(self.legend_settings)
        self.legend_settings.setVisible(False)

        # Create chart view with the chart
        self.chart_view = QtCharts.QChartView(self.chart, self)

        # Create spinbox to modify font size
        self.font_size.setValue(self.chart.legend().font().pointSizeF())
        self.font_size.valueChanged.connect(self.font_size_changed)

        self.font_layout.addRow("Legend font size", self.font_size)

        # Create layout for grid and detached legend
        self.main_layout.addLayout(self.button_layout, 0, 0)
        self.main_layout.addLayout(self.font_layout, 1, 0)
        self.main_layout.addWidget(self.chart_view, 0, 1, 3, 1)
        self.setLayout(self.main_layout)

        self.create_series()
Ejemplo n.º 22
0
    def plotAllExpenseBars(self, legendPlot=None):
        chart = QtCharts.QChart()

        barSets = []
        barSeries = QtCharts.QBarSeries()
        maxVal = 0
        if legendPlot is None:
            catList = ['Alle']
            for cat in list(self.plotData.keys()):
                if cat == "Einnahmen" or cat == "Zählerstände":
                    continue
                barSet = QtCharts.QBarSet(cat)
                barSet.append(self.plotData[cat])
                barSets.append(barSet)
                barSeries.append(barSet)
                catList.append(cat)
                maxVal = max(maxVal, max(self.plotData[cat]))
            self.barSets = barSets
            self.catList = catList
        else:
            barSet = QtCharts.QBarSet(legendPlot)
            barSet.append(self.plotData[legendPlot])
            barSets.append(barSet)
            barSeries.append(barSet)
            maxVal = max(self.plotData[legendPlot])

        chart.addSeries(barSeries)

        titleFont = QFont("Sans Serif")
        titleFont.setPointSize(16)
        titleFont.setBold(True)
        chart.setTitleFont(titleFont)
        if legendPlot is None:
            chart.setTitle("Ausgaben")
        else:
            chart.setTitle("Ausgaben: " + legendPlot)

        axisX = QtCharts.QBarCategoryAxis()
        axisX.append(self.plotDataTags)
        chart.setAxisX(axisX, barSeries)
        # axisX.setRange(self.plotDataTags[0], self.plotDataTags[-1])

        axisY = QtCharts.QValueAxis()
        axisY.setLabelFormat("%i")
        axisY.setTitleText("€")
        self.setYRange(maxVal, axisY)
        # chart.setAxisY(axisY, lineSeries)
        chart.setAxisY(axisY, barSeries)
        # axisY.setRange(0, 20)

        if legendPlot is None:
            chart.legend().setVisible(True)
            chart.legend().setAlignment(Qt.AlignRight)
        else:
            chart.legend().setVisible(False)

        self.setChart(chart)
        self.setRenderHint(QPainter.Antialiasing)
        if legendPlot is None:
            self.sgn_updateLegendSelection.emit(self.catList)
        # draw the plot from scratch (if that makes a difference)
        print('Expense bar plot drawn')
Ejemplo n.º 23
0
    def createChart(self, title, days, type, db):

        with open('config.json', 'r') as f:
            config = json.load(f)
            names = config['SEARCH']

        if (type == "lines"):
            datesLookUp = self.DateSeriesMongoDB(
                self.calcultateFirstDate(days))
            datesAvailable = self.datesWithData(datesLookUp, db, title)

            series = []

            for name in names:
                newSeries = QtCharts.QLineSeries()
                newSeries.setName(name)
                #series.append(self.fillLineSeries(newSeries, datesLookUp, db, title))
                series.append(
                    self.fillLineSeries(newSeries, datesAvailable, db, title,
                                        name))

            chart = QtCharts.QChart()
            for serie in series:
                chart.addSeries(serie)

            chart.setTitle(title)

            #datesAxis = self.calculateDateSeries(self.calcultateFirstDate(days))
            print(datesAvailable)
            datesAxis = [dt.strftime("%m-%d") for dt in datesAvailable]
            print(datesAxis)
            chart.createDefaultAxes()
            axisX = QtCharts.QBarCategoryAxis()
            axisY = QtCharts.QValueAxis()
            axisX.append(datesAxis)
            axisX.setRange(datesAxis[0], datesAxis[len(datesAxis) - 1])

            for serie in series:
                chart.setAxisX(axisX, serie)
                chart.setAxisY(axisY, serie)

            chart.legend().setVisible(True)
            chart.legend().setAlignment(Qt.AlignBottom)
            chartView = QtCharts.QChartView(chart)
            chartView.setMinimumSize(700, 500)
            chartView.setRenderHint(QPainter.Antialiasing)

            return chartView

        elif (type == "bars"):

            datesLookUp = self.DateSeriesMongoDB(
                self.calcultateFirstDate(days))
            datesAvailable = self.datesWithData(datesLookUp, db, title)

            series = []

            for name in names:
                newSeries = QtCharts.QBarSet(name)
                #series.append(self.fillBarSeries(newSeries, datesLookUp, db, title))
                series.append(
                    self.fillBarSeries(newSeries, datesAvailable, db, title,
                                       name))

            chart = QtCharts.QChart()
            barSeries = QtCharts.QBarSeries()
            for serie in series:
                barSeries.append(serie)

            chart.setTitle(title)
            chart.addSeries(barSeries)

            #datesAxis = self.calculateDateSeries(self.calcultateFirstDate(days))
            datesAxis = [dt.strftime("%m-%d") for dt in datesAvailable]
            chart.createDefaultAxes()

            axisX = QtCharts.QBarCategoryAxis()
            axisX.append(datesAxis)
            chart.setAxisX(axisX, barSeries)
            axisX.setRange(datesAxis[0], datesAxis[len(datesAxis) - 1])

            axisY = QtCharts.QValueAxis()

            chart.legend().setVisible(True)
            chart.legend().setAlignment(Qt.AlignBottom)
            chartView = QtCharts.QChartView(chart)
            chartView.setMinimumSize(700, 500)
            chartView.setRenderHint(QPainter.Antialiasing)

            return chartView

        elif (type == "percentage"):

            datesLookUp = self.DateSeriesMongoDB(
                self.calcultateFirstDate(days))
            datesAvailable = self.datesWithData(datesLookUp, db, title)
            #datesAxis = self.calculateDateSeries(self.calcultateFirstDate(days))
            datesAxis = [dt.strftime("%m-%d") for dt in datesAvailable]

            series = []

            for name in names:
                newSeries = QtCharts.QBarSet(name)
                #series.append(self.fillBarSeries(newSeries, datesLookUp, db, title))
                series.append(
                    self.fillBarSeries(newSeries, datesAvailable, db, title,
                                       name))

            if (len(names) == 1):
                filler = QtCharts.QBarSet("")
                filler.append([100 for item in range(0, len(datesAxis))])
                series.append(filler)

            chart = QtCharts.QChart()
            percentBarSeries = QtCharts.QPercentBarSeries()
            for serie in series:
                percentBarSeries.append(serie)

            chart.setTitle(title)
            chart.addSeries(percentBarSeries)

            chart.createDefaultAxes()

            axisX = QtCharts.QBarCategoryAxis()
            axisX.append(datesAxis)
            chart.setAxisX(axisX, percentBarSeries)
            axisX.setRange(datesAxis[0], datesAxis[len(datesAxis) - 1])

            axisY = QtCharts.QValueAxis()

            chart.legend().setVisible(True)
            chart.legend().setAlignment(Qt.AlignBottom)
            chartView = QtCharts.QChartView(chart)
            chartView.setMinimumSize(700, 500)
            chartView.setRenderHint(QPainter.Antialiasing)

            return chartView
        elif (type == "schedule"):

            datesLookUp = self.DateSeriesMongoDB(
                self.calcultateFirstDate(days))
            datesAvailable = self.datesWithData(datesLookUp, db, title)
            series = []

            for name in names:
                newSeries = QtCharts.QBarSet(name)
                #series.append(self.fillScheduleSeries(newSeries, datesLookUp, db, title))
                series.append(
                    self.fillScheduleSeries(newSeries, datesAvailable, db,
                                            title, name))

            chart = QtCharts.QChart()
            barSeries = QtCharts.QBarSeries()
            for serie in series:
                barSeries.append(serie)

            chart.setTitle(title)
            #datesAxis = self.scheduleAxis(newSeries, datesLookUp, db, title)
            datesAxis = self.scheduleAxis(newSeries, datesAvailable, db, title)
            chart.addSeries(barSeries)

            chart.createDefaultAxes()

            axisX = QtCharts.QBarCategoryAxis()
            axisX.append(datesAxis)
            chart.setAxisX(axisX, barSeries)
            axisX.setRange(datesAxis[0], datesAxis[len(datesAxis) - 1])

            axisY = QtCharts.QValueAxis()

            chart.legend().setVisible(True)
            chart.legend().setAlignment(Qt.AlignBottom)
            chartView = QtCharts.QChartView(chart)
            chartView.setMinimumSize(700, 500)
            #chartView.setMaximumSize(1000,500)
            chartView.setRenderHint(QPainter.Antialiasing)

            return chartView
        else:
            raise "Wrong chart type"