I have this code:
data = go.Scatter(
x=positionsX,
y=positionsY,
textposition='middle center',
mode='markers+text',
marker=dict(
color=color,
opacity=[1, 1, 1, 1, 1],
size=[100, 70, 60, 30, 25]),
text=list(sumByRegion.keys()),
)
and I wanna change the textposition to 'bottom left' based on sumByRegion.keys() value.
sumByRegion.keys() is dict_values([55, 24, 16, 3, 2])
What I have now is on the image:
image
edit:
Actually, I was looking for set the textposition for each individual item. Therefore, I used a array of textposition to fix the problem.
data = go.Scatter(
x=positionsX,
y=positionsY,
textposition=["middle center", "middle center", "middle center", "middle right", "middle left"],
mode='markers+text',
marker=dict(
color=color,
opacity=[1, 1, 1, 1, 1],
size=[100, 70, 60, 30, 25]),
text=list(sumByRegion.keys()),
)
If the text you want to display is in dictionary format, then you can convert it to the format you want to display. I'm not sure what the desired format is, but I added a line break and added a percent sign.
import plotly.graph_objects as go
sumByRegion = {'USA':55,'EU':24,'Asia':16,'Africa':2,'South America':3}
text = {'{}<br>{}%'.format(k,v) for k,v in zip(sumByRegion.keys(), sumByRegion.values())}
data = go.Scatter(
x=positionsX,
y=positionsY,
textposition='bottom left',
mode='markers+text',
marker=dict(
color=color,
opacity=[1, 1, 1, 1, 1],
size=[100, 70, 60, 30, 25]),
text=text,
)
I want to show a few data on the screen (These are inputs and outputs from RPi).
I also want to show a chart. (I got sample code here https://codeloop.org/pyqtchart-how-to-create-barchart-in-pyqt5/)
I am having one issue though. I am not able to get the widgets resize when the screen resizes. Even when maximized the size remains the same.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'prodwindowui3.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QChart, QChartView, QBarSet, QPercentBarSeries, QBarCategoryAxis
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import QWidget
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(923, 480)
MainWindow.setLayoutDirection(QtCore.Qt.LeftToRight)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(50, 10, 751, 31))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.lytHTitle = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.lytHTitle.setContentsMargins(0, 0, 0, 0)
self.lytHTitle.setObjectName("lytHTitle")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.lytHTitle.addItem(spacerItem)
self.lblTitle = QtWidgets.QLabel(self.horizontalLayoutWidget)
self.lblTitle.setObjectName("lblTitle")
self.lytHTitle.addWidget(self.lblTitle)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.lytHTitle.addItem(spacerItem1)
self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(0, 40, 791, 241))
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
self.lytH_Top = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
self.lytH_Top.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
self.lytH_Top.setContentsMargins(0, 0, 0, 0)
self.lytH_Top.setSpacing(10)
self.lytH_Top.setObjectName("lytH_Top")
self.frmInput = QtWidgets.QFrame(self.horizontalLayoutWidget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(5)
sizePolicy.setVerticalStretch(12)
sizePolicy.setHeightForWidth(self.frmInput.sizePolicy().hasHeightForWidth())
self.frmInput.setSizePolicy(sizePolicy)
self.frmInput.setMinimumSize(QtCore.QSize(95, 208))
self.frmInput.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmInput.setFrameShape(QtWidgets.QFrame.Box)
self.frmInput.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmInput.setLineWidth(1)
self.frmInput.setObjectName("frmInput")
self.layoutWidget_5 = QtWidgets.QWidget(self.frmInput)
self.layoutWidget_5.setGeometry(QtCore.QRect(10, 10, 35, 178))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.lytV_Input_label_3 = QtWidgets.QVBoxLayout(self.layoutWidget_5)
self.lytV_Input_label_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_label_3.setSpacing(12)
self.lytV_Input_label_3.setObjectName("lytV_Input_label_3")
self.lblInput0_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput0_3.setObjectName("lblInput0_3")
self.lytV_Input_label_3.addWidget(self.lblInput0_3)
self.lblInput1_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput1_3.setObjectName("lblInput1_3")
self.lytV_Input_label_3.addWidget(self.lblInput1_3)
self.lblInput2_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput2_3.setObjectName("lblInput2_3")
self.lytV_Input_label_3.addWidget(self.lblInput2_3)
self.lblInput3_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput3_3.setObjectName("lblInput3_3")
self.lytV_Input_label_3.addWidget(self.lblInput3_3)
self.layoutWidget_6 = QtWidgets.QWidget(self.frmInput)
self.layoutWidget_6.setGeometry(QtCore.QRect(40, 10, 46, 178))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.lytV_Input_Status_3 = QtWidgets.QVBoxLayout(self.layoutWidget_6)
self.lytV_Input_Status_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_Status_3.setSpacing(12)
self.lytV_Input_Status_3.setObjectName("lytV_Input_Status_3")
self.lblInput0_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput0_Status_3.setObjectName("lblInput0_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput0_Status_3)
self.lblInput1_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput1_Status_3.setObjectName("lblInput1_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput1_Status_3)
self.lblInput2_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput2_Status_3.setObjectName("lblInput2_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput2_Status_3)
self.lblInput3_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput3_Status_3.setObjectName("lblInput3_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput3_Status_3)
self.lblOStatus_2 = QtWidgets.QLabel(self.frmInput)
self.lblOStatus_2.setGeometry(QtCore.QRect(30, 190, 30, 10))
self.lblOStatus_2.setStyleSheet("Font:Bold;")
self.lblOStatus_2.setObjectName("lblOStatus_2")
self.lytH_Top.addWidget(self.frmInput)
self.frmOutput = QtWidgets.QFrame(self.horizontalLayoutWidget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frmOutput.sizePolicy().hasHeightForWidth())
self.frmOutput.setSizePolicy(sizePolicy)
self.frmOutput.setMinimumSize(QtCore.QSize(95, 208))
self.frmOutput.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmOutput.setFrameShape(QtWidgets.QFrame.Box)
self.frmOutput.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmOutput.setLineWidth(1)
self.frmOutput.setObjectName("frmOutput")
self.verticalLayoutWidget_22 = QtWidgets.QWidget(self.frmOutput)
self.verticalLayoutWidget_22.setGeometry(QtCore.QRect(50, 10, 41, 178))
self.verticalLayoutWidget_22.setObjectName("verticalLayoutWidget_22")
self.lytV_Output_Status_3 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_22)
self.lytV_Output_Status_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Output_Status_3.setSpacing(12)
self.lytV_Output_Status_3.setObjectName("lytV_Output_Status_3")
self.lblOutput0_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput0_Status_3.setObjectName("lblOutput0_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput0_Status_3)
self.lblOutput1_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput1_Status_3.setObjectName("lblOutput1_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput1_Status_3)
self.lblOutput2_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput2_Status_3.setObjectName("lblOutput2_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput2_Status_3)
self.lblOutput3_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput3_Status_3.setObjectName("lblOutput3_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput3_Status_3)
self.verticalLayoutWidget_23 = QtWidgets.QWidget(self.frmOutput)
self.verticalLayoutWidget_23.setGeometry(QtCore.QRect(10, 10, 41, 178))
self.verticalLayoutWidget_23.setObjectName("verticalLayoutWidget_23")
self.lytV_Output_Label_3 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_23)
self.lytV_Output_Label_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Output_Label_3.setSpacing(12)
self.lytV_Output_Label_3.setObjectName("lytV_Output_Label_3")
self.lblOutput0_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput0_3.setObjectName("lblOutput0_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput0_3)
self.lblOutput1_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput1_3.setObjectName("lblOutput1_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput1_3)
self.lblOutput2_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput2_3.setObjectName("lblOutput2_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput2_3)
self.lblOutput3_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput3_3.setObjectName("lblOutput3_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput3_3)
self.lblOStatus_3 = QtWidgets.QLabel(self.frmOutput)
self.lblOStatus_3.setGeometry(QtCore.QRect(240, 190, 30, 10))
self.lblOStatus_3.setStyleSheet("Font:Bold;")
self.lblOStatus_3.setObjectName("lblOStatus_3")
self.lblOStatus_4 = QtWidgets.QLabel(self.frmOutput)
self.lblOStatus_4.setGeometry(QtCore.QRect(30, 190, 41, 10))
self.lblOStatus_4.setStyleSheet("Font:Bold;")
self.lblOStatus_4.setObjectName("lblOStatus_4")
self.lytH_Top.addWidget(self.frmOutput)
self.frmInput_2 = QtWidgets.QFrame(self.horizontalLayoutWidget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(5)
sizePolicy.setVerticalStretch(12)
sizePolicy.setHeightForWidth(self.frmInput_2.sizePolicy().hasHeightForWidth())
self.frmInput_2.setSizePolicy(sizePolicy)
self.frmInput_2.setMinimumSize(QtCore.QSize(95, 208))
self.frmInput_2.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmInput_2.setFrameShape(QtWidgets.QFrame.Box)
self.frmInput_2.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmInput_2.setLineWidth(1)
self.frmInput_2.setObjectName("frmInput_2")
self.layoutWidget_7 = QtWidgets.QWidget(self.frmInput_2)
self.layoutWidget_7.setGeometry(QtCore.QRect(10, 10, 35, 178))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.lytV_Input_label_4 = QtWidgets.QVBoxLayout(self.layoutWidget_7)
self.lytV_Input_label_4.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_label_4.setSpacing(12)
self.lytV_Input_label_4.setObjectName("lytV_Input_label_4")
self.lblInput0_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput0_4.setObjectName("lblInput0_4")
self.lytV_Input_label_4.addWidget(self.lblInput0_4)
self.lblInput1_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput1_4.setObjectName("lblInput1_4")
self.lytV_Input_label_4.addWidget(self.lblInput1_4)
self.lblInput2_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput2_4.setObjectName("lblInput2_4")
self.lytV_Input_label_4.addWidget(self.lblInput2_4)
self.lblInput3_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput3_4.setObjectName("lblInput3_4")
self.lytV_Input_label_4.addWidget(self.lblInput3_4)
self.layoutWidget_8 = QtWidgets.QWidget(self.frmInput_2)
self.layoutWidget_8.setGeometry(QtCore.QRect(40, 10, 46, 178))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.lytV_Input_Status_4 = QtWidgets.QVBoxLayout(self.layoutWidget_8)
self.lytV_Input_Status_4.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_Status_4.setSpacing(12)
self.lytV_Input_Status_4.setObjectName("lytV_Input_Status_4")
self.lblInput0_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput0_Status_4.setObjectName("lblInput0_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput0_Status_4)
self.lblInput1_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput1_Status_4.setObjectName("lblInput1_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput1_Status_4)
self.lblInput2_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput2_Status_4.setObjectName("lblInput2_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput2_Status_4)
self.lblInput3_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput3_Status_4.setObjectName("lblInput3_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput3_Status_4)
self.lblOStatus_5 = QtWidgets.QLabel(self.frmInput_2)
self.lblOStatus_5.setGeometry(QtCore.QRect(30, 190, 30, 10))
self.lblOStatus_5.setStyleSheet("Font:Bold;")
self.lblOStatus_5.setObjectName("lblOStatus_5")
self.lytH_Top.addWidget(self.frmInput_2)
self.frmInput_3 = QtWidgets.QFrame(self.horizontalLayoutWidget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(5)
sizePolicy.setVerticalStretch(12)
sizePolicy.setHeightForWidth(self.frmInput_3.sizePolicy().hasHeightForWidth())
self.frmInput_3.setSizePolicy(sizePolicy)
self.frmInput_3.setMinimumSize(QtCore.QSize(95, 208))
self.frmInput_3.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmInput_3.setFrameShape(QtWidgets.QFrame.Box)
self.frmInput_3.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmInput_3.setLineWidth(1)
self.frmInput_3.setObjectName("frmInput_3")
self.layoutWidget_9 = QtWidgets.QWidget(self.frmInput_3)
self.layoutWidget_9.setGeometry(QtCore.QRect(10, 10, 35, 178))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.lytV_Input_label_5 = QtWidgets.QVBoxLayout(self.layoutWidget_9)
self.lytV_Input_label_5.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_label_5.setSpacing(12)
self.lytV_Input_label_5.setObjectName("lytV_Input_label_5")
self.lblInput0_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput0_5.setObjectName("lblInput0_5")
self.lytV_Input_label_5.addWidget(self.lblInput0_5)
self.lblInput1_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput1_5.setObjectName("lblInput1_5")
self.lytV_Input_label_5.addWidget(self.lblInput1_5)
self.lblInput2_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput2_5.setObjectName("lblInput2_5")
self.lytV_Input_label_5.addWidget(self.lblInput2_5)
self.lblInput3_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput3_5.setObjectName("lblInput3_5")
self.lytV_Input_label_5.addWidget(self.lblInput3_5)
self.layoutWidget_10 = QtWidgets.QWidget(self.frmInput_3)
self.layoutWidget_10.setGeometry(QtCore.QRect(40, 10, 46, 178))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.lytV_Input_Status_5 = QtWidgets.QVBoxLayout(self.layoutWidget_10)
self.lytV_Input_Status_5.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_Status_5.setSpacing(12)
self.lytV_Input_Status_5.setObjectName("lytV_Input_Status_5")
self.lblInput0_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput0_Status_5.setObjectName("lblInput0_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput0_Status_5)
self.lblInput1_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput1_Status_5.setObjectName("lblInput1_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput1_Status_5)
self.lblInput2_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput2_Status_5.setObjectName("lblInput2_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput2_Status_5)
self.lblInput3_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput3_Status_5.setObjectName("lblInput3_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput3_Status_5)
self.lblOStatus_6 = QtWidgets.QLabel(self.frmInput_3)
self.lblOStatus_6.setGeometry(QtCore.QRect(30, 190, 30, 10))
self.lblOStatus_6.setStyleSheet("Font:Bold;")
self.lblOStatus_6.setObjectName("lblOStatus_6")
self.lytH_Top.addWidget(self.frmInput_3)
self.lytH_Top.setStretch(0, 10)
self.lytH_Top.setStretch(1, 10)
self.horizontalLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_3.setGeometry(QtCore.QRect(10, 290, 791, 210))
self.horizontalLayoutWidget_3.setObjectName("horizontalLayoutWidget_3")
self.lytH_Chart = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_3)
self.lytH_Chart.setContentsMargins(1, 0, 0, 0)
self.lytH_Chart.setSpacing(3)
self.lytH_Chart.setObjectName("lytH_Chart")
self.widget_Chart = QtWidgets.QWidget(self.horizontalLayoutWidget_3)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget_Chart.sizePolicy().hasHeightForWidth())
self.widget_Chart.setSizePolicy(sizePolicy)
self.widget_Chart.setObjectName("widget_Chart")
self.lytH_Chart.addWidget(self.widget_Chart)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 923, 18))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.lblTitle.setText(_translate("MainWindow",
"<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\">TEST DATA SHOW</span></p></body></html>"))
self.lblInput0_3.setText(_translate("MainWindow", "Input0"))
self.lblInput1_3.setText(_translate("MainWindow", "Input1"))
self.lblInput2_3.setText(_translate("MainWindow", "Input2"))
self.lblInput3_3.setText(_translate("MainWindow", "Input3"))
self.lblInput0_Status_3.setText(_translate("MainWindow", "0"))
self.lblInput1_Status_3.setText(_translate("MainWindow", "0"))
self.lblInput2_Status_3.setText(_translate("MainWindow", "0"))
self.lblInput3_Status_3.setText(_translate("MainWindow", "0"))
self.lblOStatus_2.setText(_translate("MainWindow", "INPUT"))
self.lblOutput0_Status_3.setText(_translate("MainWindow", "0"))
self.lblOutput1_Status_3.setText(_translate("MainWindow", "0"))
self.lblOutput2_Status_3.setText(_translate("MainWindow", "0"))
self.lblOutput3_Status_3.setText(_translate("MainWindow", "0"))
self.lblOutput0_3.setText(_translate("MainWindow", "Output0"))
self.lblOutput1_3.setText(_translate("MainWindow", "Output1"))
self.lblOutput2_3.setText(_translate("MainWindow", "Output2"))
self.lblOutput3_3.setText(_translate("MainWindow", "Output3"))
self.lblOStatus_3.setText(_translate("MainWindow", "INPUT"))
self.lblOStatus_4.setText(_translate("MainWindow", "<html><head/><body><p>OUTPUT</p></body></html>"))
self.lblInput0_4.setText(_translate("MainWindow", "Input0"))
self.lblInput1_4.setText(_translate("MainWindow", "Input1"))
self.lblInput2_4.setText(_translate("MainWindow", "Input2"))
self.lblInput3_4.setText(_translate("MainWindow", "Input3"))
self.lblInput0_Status_4.setText(_translate("MainWindow", "0"))
self.lblInput1_Status_4.setText(_translate("MainWindow", "0"))
self.lblInput2_Status_4.setText(_translate("MainWindow", "0"))
self.lblInput3_Status_4.setText(_translate("MainWindow", "0"))
self.lblOStatus_5.setText(_translate("MainWindow", "INPUT"))
self.lblInput0_5.setText(_translate("MainWindow", "Input0"))
self.lblInput1_5.setText(_translate("MainWindow", "Input1"))
self.lblInput2_5.setText(_translate("MainWindow", "Input2"))
self.lblInput3_5.setText(_translate("MainWindow", "Input3"))
self.lblInput0_Status_5.setText(_translate("MainWindow", "0"))
self.lblInput1_Status_5.setText(_translate("MainWindow", "0"))
self.lblInput2_Status_5.setText(_translate("MainWindow", "0"))
self.lblInput3_Status_5.setText(_translate("MainWindow", "0"))
self.lblOStatus_6.setText(_translate("MainWindow", "INPUT"))
def create_bar(self):
# The QBarSet class represents a set of bars in the bar chart.
# It groups several bars into a bar set
set0 = QBarSet("Parwiz")
set1 = QBarSet("Bob")
set2 = QBarSet("Tom")
set3 = QBarSet("Logan")
set4 = QBarSet("Karim")
set0 << 1 << 2 << 3 << 4 << 5 << 6
set1 << 5 << 0 << 0 << 4 << 0 << 7
set2 << 3 << 5 << 8 << 13 << 8 << 5
set3 << 5 << 6 << 7 << 3 << 4 << 5
set4 << 9 << 7 << 5 << 3 << 1 << 2
series = QPercentBarSeries()
series.append(set0)
series.append(set1)
series.append(set2)
series.append(set3)
series.append(set4)
chart = QChart()
chart.addSeries(series)
chart.setTitle("Percent Example")
chart.setAnimationOptions(QChart.SeriesAnimations)
categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
axis = QBarCategoryAxis()
axis.append(categories)
chart.createDefaultAxes()
chart.setAxisX(axis, series)
chart.legend().setVisible(True)
chart.legend().setAlignment(Qt.AlignBottom)
chartView = QChartView(chart)
chartView.setRenderHint(QPainter.Antialiasing)
self.lytH_Chart.addWidget(chartView)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
ui.create_bar()
MainWindow.show()
sys.exit(app.exec_())
I am using QFrame to show a box around each set of Data. I tried to set the Horizontal and Vertical Policy under size policy as expanding also.
Nothing happens. I even used horizontal spacers.
Can some please guide. Thanks
Ok. I am still learning the QT Designer. I could find out the problem.
In fact the 3 Horizontal layouts should go into a main layout (I used a vertical layout).
This solved my problem.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'prodialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QChart, QChartView, QBarSet, QPercentBarSeries, QBarCategoryAxis
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import QWidget
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(941, 545)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.lytHTitle = QtWidgets.QHBoxLayout()
self.lytHTitle.setObjectName("lytHTitle")
self.lblTitle = QtWidgets.QLabel(Dialog)
self.lblTitle.setObjectName("lblTitle")
self.lytHTitle.addWidget(self.lblTitle)
self.verticalLayout.addLayout(self.lytHTitle)
self.lytH_Top = QtWidgets.QHBoxLayout()
self.lytH_Top.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
self.lytH_Top.setSpacing(10)
self.lytH_Top.setObjectName("lytH_Top")
self.frmInput = QtWidgets.QFrame(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frmInput.sizePolicy().hasHeightForWidth())
self.frmInput.setSizePolicy(sizePolicy)
self.frmInput.setMinimumSize(QtCore.QSize(95, 208))
self.frmInput.setMaximumSize(QtCore.QSize(120, 208))
self.frmInput.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmInput.setFrameShape(QtWidgets.QFrame.Box)
self.frmInput.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmInput.setLineWidth(1)
self.frmInput.setObjectName("frmInput")
self.layoutWidget_5 = QtWidgets.QWidget(self.frmInput)
self.layoutWidget_5.setGeometry(QtCore.QRect(10, 10, 35, 178))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.lytV_Input_label_3 = QtWidgets.QVBoxLayout(self.layoutWidget_5)
self.lytV_Input_label_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_label_3.setSpacing(12)
self.lytV_Input_label_3.setObjectName("lytV_Input_label_3")
self.lblInput0_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput0_3.setObjectName("lblInput0_3")
self.lytV_Input_label_3.addWidget(self.lblInput0_3)
self.lblInput1_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput1_3.setObjectName("lblInput1_3")
self.lytV_Input_label_3.addWidget(self.lblInput1_3)
self.lblInput2_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput2_3.setObjectName("lblInput2_3")
self.lytV_Input_label_3.addWidget(self.lblInput2_3)
self.lblInput3_3 = QtWidgets.QLabel(self.layoutWidget_5)
self.lblInput3_3.setObjectName("lblInput3_3")
self.lytV_Input_label_3.addWidget(self.lblInput3_3)
self.layoutWidget_6 = QtWidgets.QWidget(self.frmInput)
self.layoutWidget_6.setGeometry(QtCore.QRect(40, 10, 46, 178))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.lytV_Input_Status_3 = QtWidgets.QVBoxLayout(self.layoutWidget_6)
self.lytV_Input_Status_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_Status_3.setSpacing(12)
self.lytV_Input_Status_3.setObjectName("lytV_Input_Status_3")
self.lblInput0_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput0_Status_3.setObjectName("lblInput0_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput0_Status_3)
self.lblInput1_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput1_Status_3.setObjectName("lblInput1_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput1_Status_3)
self.lblInput2_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput2_Status_3.setObjectName("lblInput2_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput2_Status_3)
self.lblInput3_Status_3 = QtWidgets.QLabel(self.layoutWidget_6)
self.lblInput3_Status_3.setObjectName("lblInput3_Status_3")
self.lytV_Input_Status_3.addWidget(self.lblInput3_Status_3)
self.lblOStatus_2 = QtWidgets.QLabel(self.frmInput)
self.lblOStatus_2.setGeometry(QtCore.QRect(30, 190, 30, 10))
self.lblOStatus_2.setStyleSheet("Font:Bold;")
self.lblOStatus_2.setObjectName("lblOStatus_2")
self.lytH_Top.addWidget(self.frmInput)
self.frmOutput = QtWidgets.QFrame(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frmOutput.sizePolicy().hasHeightForWidth())
self.frmOutput.setSizePolicy(sizePolicy)
self.frmOutput.setMinimumSize(QtCore.QSize(95, 208))
self.frmOutput.setMaximumSize(QtCore.QSize(120, 208))
self.frmOutput.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmOutput.setFrameShape(QtWidgets.QFrame.Box)
self.frmOutput.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmOutput.setLineWidth(1)
self.frmOutput.setObjectName("frmOutput")
self.verticalLayoutWidget_22 = QtWidgets.QWidget(self.frmOutput)
self.verticalLayoutWidget_22.setGeometry(QtCore.QRect(50, 10, 41, 178))
self.verticalLayoutWidget_22.setObjectName("verticalLayoutWidget_22")
self.lytV_Output_Status_3 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_22)
self.lytV_Output_Status_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Output_Status_3.setSpacing(12)
self.lytV_Output_Status_3.setObjectName("lytV_Output_Status_3")
self.lblOutput0_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput0_Status_3.setObjectName("lblOutput0_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput0_Status_3)
self.lblOutput1_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput1_Status_3.setObjectName("lblOutput1_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput1_Status_3)
self.lblOutput2_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput2_Status_3.setObjectName("lblOutput2_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput2_Status_3)
self.lblOutput3_Status_3 = QtWidgets.QLabel(self.verticalLayoutWidget_22)
self.lblOutput3_Status_3.setObjectName("lblOutput3_Status_3")
self.lytV_Output_Status_3.addWidget(self.lblOutput3_Status_3)
self.verticalLayoutWidget_23 = QtWidgets.QWidget(self.frmOutput)
self.verticalLayoutWidget_23.setGeometry(QtCore.QRect(10, 10, 41, 178))
self.verticalLayoutWidget_23.setObjectName("verticalLayoutWidget_23")
self.lytV_Output_Label_3 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_23)
self.lytV_Output_Label_3.setContentsMargins(7, 3, 4, 4)
self.lytV_Output_Label_3.setSpacing(12)
self.lytV_Output_Label_3.setObjectName("lytV_Output_Label_3")
self.lblOutput0_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput0_3.setObjectName("lblOutput0_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput0_3)
self.lblOutput1_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput1_3.setObjectName("lblOutput1_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput1_3)
self.lblOutput2_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput2_3.setObjectName("lblOutput2_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput2_3)
self.lblOutput3_3 = QtWidgets.QLabel(self.verticalLayoutWidget_23)
self.lblOutput3_3.setObjectName("lblOutput3_3")
self.lytV_Output_Label_3.addWidget(self.lblOutput3_3)
self.lblOStatus_3 = QtWidgets.QLabel(self.frmOutput)
self.lblOStatus_3.setGeometry(QtCore.QRect(240, 190, 30, 10))
self.lblOStatus_3.setStyleSheet("Font:Bold;")
self.lblOStatus_3.setObjectName("lblOStatus_3")
self.lblOStatus_4 = QtWidgets.QLabel(self.frmOutput)
self.lblOStatus_4.setGeometry(QtCore.QRect(30, 190, 41, 10))
self.lblOStatus_4.setStyleSheet("Font:Bold;")
self.lblOStatus_4.setObjectName("lblOStatus_4")
self.lytH_Top.addWidget(self.frmOutput)
self.frmInput_2 = QtWidgets.QFrame(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frmInput_2.sizePolicy().hasHeightForWidth())
self.frmInput_2.setSizePolicy(sizePolicy)
self.frmInput_2.setMinimumSize(QtCore.QSize(95, 208))
self.frmInput_2.setMaximumSize(QtCore.QSize(120, 208))
self.frmInput_2.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmInput_2.setFrameShape(QtWidgets.QFrame.Box)
self.frmInput_2.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmInput_2.setLineWidth(1)
self.frmInput_2.setObjectName("frmInput_2")
self.layoutWidget_7 = QtWidgets.QWidget(self.frmInput_2)
self.layoutWidget_7.setGeometry(QtCore.QRect(10, 10, 35, 178))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.lytV_Input_label_4 = QtWidgets.QVBoxLayout(self.layoutWidget_7)
self.lytV_Input_label_4.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_label_4.setSpacing(12)
self.lytV_Input_label_4.setObjectName("lytV_Input_label_4")
self.lblInput0_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput0_4.setObjectName("lblInput0_4")
self.lytV_Input_label_4.addWidget(self.lblInput0_4)
self.lblInput1_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput1_4.setObjectName("lblInput1_4")
self.lytV_Input_label_4.addWidget(self.lblInput1_4)
self.lblInput2_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput2_4.setObjectName("lblInput2_4")
self.lytV_Input_label_4.addWidget(self.lblInput2_4)
self.lblInput3_4 = QtWidgets.QLabel(self.layoutWidget_7)
self.lblInput3_4.setObjectName("lblInput3_4")
self.lytV_Input_label_4.addWidget(self.lblInput3_4)
self.layoutWidget_8 = QtWidgets.QWidget(self.frmInput_2)
self.layoutWidget_8.setGeometry(QtCore.QRect(40, 10, 46, 178))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.lytV_Input_Status_4 = QtWidgets.QVBoxLayout(self.layoutWidget_8)
self.lytV_Input_Status_4.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_Status_4.setSpacing(12)
self.lytV_Input_Status_4.setObjectName("lytV_Input_Status_4")
self.lblInput0_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput0_Status_4.setObjectName("lblInput0_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput0_Status_4)
self.lblInput1_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput1_Status_4.setObjectName("lblInput1_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput1_Status_4)
self.lblInput2_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput2_Status_4.setObjectName("lblInput2_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput2_Status_4)
self.lblInput3_Status_4 = QtWidgets.QLabel(self.layoutWidget_8)
self.lblInput3_Status_4.setObjectName("lblInput3_Status_4")
self.lytV_Input_Status_4.addWidget(self.lblInput3_Status_4)
self.lblOStatus_5 = QtWidgets.QLabel(self.frmInput_2)
self.lblOStatus_5.setGeometry(QtCore.QRect(30, 190, 30, 10))
self.lblOStatus_5.setStyleSheet("Font:Bold;")
self.lblOStatus_5.setObjectName("lblOStatus_5")
self.lytH_Top.addWidget(self.frmInput_2)
self.frmInput_3 = QtWidgets.QFrame(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(5)
sizePolicy.setVerticalStretch(12)
sizePolicy.setHeightForWidth(self.frmInput_3.sizePolicy().hasHeightForWidth())
self.frmInput_3.setSizePolicy(sizePolicy)
self.frmInput_3.setMinimumSize(QtCore.QSize(95, 208))
self.frmInput_3.setMaximumSize(QtCore.QSize(120, 208))
self.frmInput_3.setStyleSheet("background-color: rgb(231, 226, 255);")
self.frmInput_3.setFrameShape(QtWidgets.QFrame.Box)
self.frmInput_3.setFrameShadow(QtWidgets.QFrame.Plain)
self.frmInput_3.setLineWidth(1)
self.frmInput_3.setObjectName("frmInput_3")
self.layoutWidget_9 = QtWidgets.QWidget(self.frmInput_3)
self.layoutWidget_9.setGeometry(QtCore.QRect(10, 10, 35, 178))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.lytV_Input_label_5 = QtWidgets.QVBoxLayout(self.layoutWidget_9)
self.lytV_Input_label_5.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_label_5.setSpacing(12)
self.lytV_Input_label_5.setObjectName("lytV_Input_label_5")
self.lblInput0_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput0_5.setObjectName("lblInput0_5")
self.lytV_Input_label_5.addWidget(self.lblInput0_5)
self.lblInput1_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput1_5.setObjectName("lblInput1_5")
self.lytV_Input_label_5.addWidget(self.lblInput1_5)
self.lblInput2_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput2_5.setObjectName("lblInput2_5")
self.lytV_Input_label_5.addWidget(self.lblInput2_5)
self.lblInput3_5 = QtWidgets.QLabel(self.layoutWidget_9)
self.lblInput3_5.setObjectName("lblInput3_5")
self.lytV_Input_label_5.addWidget(self.lblInput3_5)
self.layoutWidget_10 = QtWidgets.QWidget(self.frmInput_3)
self.layoutWidget_10.setGeometry(QtCore.QRect(40, 10, 46, 178))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.lytV_Input_Status_5 = QtWidgets.QVBoxLayout(self.layoutWidget_10)
self.lytV_Input_Status_5.setContentsMargins(7, 3, 4, 4)
self.lytV_Input_Status_5.setSpacing(12)
self.lytV_Input_Status_5.setObjectName("lytV_Input_Status_5")
self.lblInput0_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput0_Status_5.setObjectName("lblInput0_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput0_Status_5)
self.lblInput1_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput1_Status_5.setObjectName("lblInput1_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput1_Status_5)
self.lblInput2_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput2_Status_5.setObjectName("lblInput2_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput2_Status_5)
self.lblInput3_Status_5 = QtWidgets.QLabel(self.layoutWidget_10)
self.lblInput3_Status_5.setObjectName("lblInput3_Status_5")
self.lytV_Input_Status_5.addWidget(self.lblInput3_Status_5)
self.lblOStatus_6 = QtWidgets.QLabel(self.frmInput_3)
self.lblOStatus_6.setGeometry(QtCore.QRect(30, 190, 30, 10))
self.lblOStatus_6.setStyleSheet("Font:Bold;")
self.lblOStatus_6.setObjectName("lblOStatus_6")
self.lytH_Top.addWidget(self.frmInput_3)
self.lytH_Top.setStretch(1, 10)
self.verticalLayout.addLayout(self.lytH_Top)
self.lytH_Chart = QtWidgets.QHBoxLayout()
self.lytH_Chart.setContentsMargins(1, -1, -1, -1)
self.lytH_Chart.setSpacing(3)
self.lytH_Chart.setObjectName("lytH_Chart")
self.widget_Chart = QtWidgets.QWidget(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget_Chart.sizePolicy().hasHeightForWidth())
self.widget_Chart.setSizePolicy(sizePolicy)
self.widget_Chart.setLayoutDirection(QtCore.Qt.LeftToRight)
self.widget_Chart.setObjectName("widget_Chart")
self.lytH_Chart.addWidget(self.widget_Chart)
self.verticalLayout.addLayout(self.lytH_Chart)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.lblTitle.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\">TEST DATA SHOW</span></p></body></html>"))
self.lblInput0_3.setText(_translate("Dialog", "Input0"))
self.lblInput1_3.setText(_translate("Dialog", "Input1"))
self.lblInput2_3.setText(_translate("Dialog", "Input2"))
self.lblInput3_3.setText(_translate("Dialog", "Input3"))
self.lblInput0_Status_3.setText(_translate("Dialog", "0"))
self.lblInput1_Status_3.setText(_translate("Dialog", "0"))
self.lblInput2_Status_3.setText(_translate("Dialog", "0"))
self.lblInput3_Status_3.setText(_translate("Dialog", "0"))
self.lblOStatus_2.setText(_translate("Dialog", "INPUT"))
self.lblOutput0_Status_3.setText(_translate("Dialog", "0"))
self.lblOutput1_Status_3.setText(_translate("Dialog", "0"))
self.lblOutput2_Status_3.setText(_translate("Dialog", "0"))
self.lblOutput3_Status_3.setText(_translate("Dialog", "0"))
self.lblOutput0_3.setText(_translate("Dialog", "Output0"))
self.lblOutput1_3.setText(_translate("Dialog", "Output1"))
self.lblOutput2_3.setText(_translate("Dialog", "Output2"))
self.lblOutput3_3.setText(_translate("Dialog", "Output3"))
self.lblOStatus_3.setText(_translate("Dialog", "INPUT"))
self.lblOStatus_4.setText(_translate("Dialog", "<html><head/><body><p>OUTPUT</p></body></html>"))
self.lblInput0_4.setText(_translate("Dialog", "Input0"))
self.lblInput1_4.setText(_translate("Dialog", "Input1"))
self.lblInput2_4.setText(_translate("Dialog", "Input2"))
self.lblInput3_4.setText(_translate("Dialog", "Input3"))
self.lblInput0_Status_4.setText(_translate("Dialog", "0"))
self.lblInput1_Status_4.setText(_translate("Dialog", "0"))
self.lblInput2_Status_4.setText(_translate("Dialog", "0"))
self.lblInput3_Status_4.setText(_translate("Dialog", "0"))
self.lblOStatus_5.setText(_translate("Dialog", "INPUT"))
self.lblInput0_5.setText(_translate("Dialog", "Input0"))
self.lblInput1_5.setText(_translate("Dialog", "Input1"))
self.lblInput2_5.setText(_translate("Dialog", "Input2"))
self.lblInput3_5.setText(_translate("Dialog", "Input3"))
self.lblInput0_Status_5.setText(_translate("Dialog", "0"))
self.lblInput1_Status_5.setText(_translate("Dialog", "0"))
self.lblInput2_Status_5.setText(_translate("Dialog", "0"))
self.lblInput3_Status_5.setText(_translate("Dialog", "0"))
self.lblOStatus_6.setText(_translate("Dialog", "INPUT"))
def create_bar(self):
# The QBarSet class represents a set of bars in the bar chart.
# It groups several bars into a bar set
set0 = QBarSet("Parwiz")
set1 = QBarSet("Bob")
set2 = QBarSet("Tom")
set3 = QBarSet("Logan")
set4 = QBarSet("Karim")
set0 << 1 << 2 << 3 << 4 << 5 << 6
set1 << 5 << 0 << 0 << 4 << 0 << 7
set2 << 3 << 5 << 8 << 13 << 8 << 5
set3 << 5 << 6 << 7 << 3 << 4 << 5
set4 << 9 << 7 << 5 << 3 << 1 << 2
series = QPercentBarSeries()
series.append(set0)
series.append(set1)
series.append(set2)
series.append(set3)
series.append(set4)
chart = QChart()
chart.addSeries(series)
chart.setTitle("Percent Example")
chart.setAnimationOptions(QChart.SeriesAnimations)
categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
axis = QBarCategoryAxis()
axis.append(categories)
chart.createDefaultAxes()
chart.setAxisX(axis, series)
chart.legend().setVisible(True)
chart.legend().setAlignment(Qt.AlignBottom)
chartView = QChartView(chart)
chartView.setRenderHint(QPainter.Antialiasing)
self.lytH_Chart.addWidget(chartView)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
ui.create_bar()
Dialog.show()
sys.exit(app.exec_())
I am using the cbar.ax.tick_params matplotlib command to make a colorbar for an XY scatterplot. How do I reverse the values (not the color-ramp) so that the lowest value is at the top of the bar. This is to represent geological data where the youngest rocks are on top of the older rocks. Here the age is represented by color.
Here is my code:
plt.scatter(summary["d18O"], summary["eHf"], s=150, c = color, cmap = color_map, edgecolors='black', marker='o')
plt.errorbar(summary["d18O"], summary["eHf"], summary["xerr"], summary["yerr"], ls='none', color='lightgrey', zorder=-1)
cbar=plt.colorbar()
cbar.ax.tick_params(labelsize=14)
cbar.minorticks_on()
cbar.set_label('Age (Ma)', style='italic', fontsize=16)
plt.axvline(x=5.3, color='black', zorder=-1)
plt.axhline(y=0, color='black', zorder=-1)
plt.tick_params(labelsize=14)
ax.set_xticks([4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
ax.set_yticks([-6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14, 16])
plt.ylabel(u'${\epsilon}$Hf$_{T}$', style='italic', fontsize=18)
plt.xlabel(u'$\delta^{18}$O$_{V-SMOW}$ ‰',style='italic', fontsize=18)
plt.text(11.5, 0.3, 'CHUR', fontsize=18)
plt.text(4.9, 5, 'mantle zircon = 5.3‰', fontsize=16, rotation=90)
plt.show()
As #r-beginners mentioned,
cbar.ax.invert_yaxis()
would solve the problem if cbar is your colorer object.
I am new to this concept and i have been trying to implement an fuzzy logic controller for shower. the input are the postion of knob from extreme left to extreme right and outputs are tempreture from very cold to very hot. i am encountering this Runtime error in the rules. Below is my stupid code
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
pos = ctrl.Consequent(np.arange(0, 180, 1), 'pos')
temp = ctrl.Consequent(np.arange(0, 100, 1), 'temp')
pos['EL'] = fuzz.trimf(pos.universe, [0, 0, 45])
pos['L'] = fuzz.trimf(pos.universe, [0, 45, 90])
pos['C'] = fuzz.trimf(pos.universe, [45, 90, 135])
pos['R'] = fuzz.trimf(pos.universe, [90, 135, 180])
pos['ER'] = fuzz.trimf(pos.universe, [135, 180, 180])
temp['VC'] = fuzz.trimf(temp.universe, [0, 0, 10])
temp['C'] = fuzz.trimf(temp.universe, [0, 10, 40])
temp['W'] = fuzz.trimf(temp.universe, [10, 40, 80])
temp['H'] = fuzz.trimf(temp.universe, [40, 80, 100])
temp['VH'] = fuzz.trimf(temp.universe, [80, 100, 100])
rule1 = ctrl.Rule(pos['EL'], temp['VC'])
rule2 = ctrl.Rule(pos['L'], temp['C'])
rule3 = ctrl.Rule(pos['C'], temp['W'])
rule4 = ctrl.Rule(pos['R'], temp['H'])
rule5 = ctrl.Rule(pos['ER'], temp['VH'])
temp_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
temprature = ctrl.ControlSystemSimulation(temp_ctrl)
RuntimeError: Unable to resolve rule execution order. The most likely reason is two or more rules that depend on each other. Please check the rule graph for loops.
I think you might want this
pos = ctrl.Consequent(np.arange(0, 180, 1), 'pos')
to be this
pos = ctrl.Antecedent(np.arange(0, 180, 1), 'pos')
so your rules will read something like
if antecedent then consequent
I'm trying to generate a stacked horizontal bar chart in matplotlib. The issue I am facing is that the width of the bars does not fully fill the available width of the plotting area (additional space on the right).
Unfortunately I couldn't find any information on this online.
What could I do to resolve this?
Chart with additional space on the right of the bars
measures = ("A", "B", "C", "D", "A", "B", "C", "D", "A", "B")
measure_bars = y_pos = np.arange(len(measures))
yes_data = [10, 10, 10, 10, 15, 10, 10, 10, 10, 10]
number_of_answers = [20, 30, 20, 20, 20, 20, 20, 20, 20, 20]
font = {'fontname': 'Arial', 'color': '#10384f'}
yes_data = [i / j * 100 for i, j in zip(yes_data, number_of_answers)]
no_data = [100 - i for i in yes_data]
bar_width = 0.6
plt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = True
plt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = False
fig = plt.figure()
plt.barh(measure_bars, yes_data, color='#89d329', height=bar_width, zorder=2)
plt.barh(measure_bars, no_data, left=yes_data, color='#ff3162', height=bar_width, zorder=3)
plt.grid(color=font["color"], zorder=0)
plt.yticks(measure_bars, measures, **font)
plt.title("TECHNICAL AND ORGANIZATIONAL MEASURES", fontweight="bold", size="16", x=0.5, y=1.1, **font)
ax = plt.axes()
ax.xaxis.set_major_formatter(PercentFormatter())
ax.spines['bottom'].set_color(font["color"])
ax.spines['top'].set_color(font["color"])
ax.spines['right'].set_color(font["color"])
ax.spines['left'].set_color(font["color"])
ax.xaxis.label.set_color(font["color"])
ax.tick_params(axis='x', colors=font["color"])
for tick in ax.get_xticklabels():
tick.set_fontname(font["fontname"])
ax.xaxis.set_ticks(np.arange(0.0, 100.1, 10))
plt.gca().legend(('Yes', 'No'), bbox_to_anchor=(0.7, 0), ncol=2, shadow=False)
plt.show()
Please add (somewhere in the middle)
ax.set_xlim(0, 1)