当前位置:网站首页>Pyqt5, draw a histogram on the control
Pyqt5, draw a histogram on the control
2022-07-01 17:09:00 【Wang Fuxing】
First, upgrade the control , Details refer to :
Upgrade the control method
And rename the control
Next, a histogram will be drawn on this control
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtChart import (QChart, QChartView, QBarSeries, QBarSet, QBarCategoryAxis, QValueAxis)
from QtCharts import Ui_MainWindow
class Window(QMainWindow, Ui_MainWindow):
def __init__(self, app):
super(QMainWindow, self).__init__()
self.app = app
self.setup_ui() # Rendering the canvas
def setup_ui(self):
self.setupUi(self) # call Ui_MainWindow Of setupUi Rendering interface
chart = QChart()
self.setting()
self.plot_view.setChart(chart)
chart.addSeries(self.series)
chart.setTitle(" Parameter index xxx")
axisY = QValueAxis()
axisY.applyNiceNumbers() # adjustment Y Axis range , Make available to display all data , Easy to watch
chart.addAxis(axisY, Qt.AlignLeft)
self.series.attachAxis(axisY) # Data is bound to the coordinate axis
self.axis_x = QBarCategoryAxis() # Add a category to the axis of the chart
daysofweek = ' Algorithm comparison '
self.axis_x.append(daysofweek)
chart.addAxis(self.axis_x, Qt.AlignBottom)
self.series.attachAxis(self.axis_x)
def setting(self):
cols = [' Algorithm 1', ' Algorithm 2', ' Algorithm 3']
data = [53, 24, 85]
self.series = QBarSeries() # Display a series of data as a vertical bar chart grouped by category
for i in range(len(cols)):
setTemp = QBarSet(cols[i]) # QBarSet Class represents a set of bars in a bar graph
temp = data[i] # Value of histogram
setTemp.append(temp)
self.series.append(setTemp)
if __name__ == "__main__":
app = QApplication(sys.argv)
mywindow = Window(app)
mywindow.show()
sys.exit(app.exec_())
This is a simple set of data , You can also draw multiple groups of data
Please refer to :
Multi group histogram
边栏推荐
猜你喜欢
PETRv2:一个多摄像头图像3D感知的统一框架
DNS
What is the effect of choosing game shield safely in the game industry?
How to use etcd to realize distributed /etc directory
SystemVerilog structure (II)
LeetCode中等题之TinyURL 的加密与解密
Sword finger offer 20 String representing numeric value
Jojogan practice
如何写出好代码 — 防御式编程指南
【C补充】【字符串】按日期排序显示一个月的日程
随机推荐
想做软件测试的女孩子看这里
[C language supplement] judge which day tomorrow is (tomorrow's date)
【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①
阿里云、追一科技抢滩对话式AI
整形数组合并【JS】
机器学习11-聚类,孤立点判别
JDBC:深入理解PreparedStatement和Statement[通俗易懂]
如何写出好代码 — 防御式编程指南
SQL question brushing 584 Looking for user references
Report on research and investment prospects of UHMWPE industry in China (2022 Edition)
存在安全隐患 起亚召回部分K3新能源
麦趣尔:媒体报道所涉两批次产品已下架封存,受理消费者诉求
Chinese diosgenin market forecast and investment strategy report (2022 Edition)
【C语言基础】12 字符串
判断二叉树是否为二叉搜索树
Pytest learning notes (13) -allure of allure Description () and @allure title()
Oom caused by improper use of multithreading
【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
Template Engine Velocity Foundation
Redis Distributed Lock