当前位置:网站首页>pyqt5中,在控件上画柱状图
pyqt5中,在控件上画柱状图
2022-07-01 16:53:00 【王龘龘】
首先将控件升级,详情参考:
将控件升级方法
并将控件改名
下面将在这个控件上画柱状图
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() # 渲染画布
def setup_ui(self):
self.setupUi(self) # 调用Ui_MainWindow的setupUi渲染界面
chart = QChart()
self.setting()
self.plot_view.setChart(chart)
chart.addSeries(self.series)
chart.setTitle("参数指标xxx")
axisY = QValueAxis()
axisY.applyNiceNumbers() # 调整Y轴范围,使可用显示所有数据,便于观看
chart.addAxis(axisY, Qt.AlignLeft)
self.series.attachAxis(axisY) # 数据与坐标轴绑定
self.axis_x = QBarCategoryAxis() # 将类别添加到图表的轴
daysofweek = '算法对比'
self.axis_x.append(daysofweek)
chart.addAxis(self.axis_x, Qt.AlignBottom)
self.series.attachAxis(self.axis_x)
def setting(self):
cols = ['算法1', '算法2', '算法3']
data = [53, 24, 85]
self.series = QBarSeries() # 将一系列数据显示为按类别分组的垂直条形图
for i in range(len(cols)):
setTemp = QBarSet(cols[i]) # QBarSet 类表示条形图中的一组条形
temp = data[i] # 柱状图的数值
setTemp.append(temp)
self.series.append(setTemp)
if __name__ == "__main__":
app = QApplication(sys.argv)
mywindow = Window(app)
mywindow.show()
sys.exit(app.exec_())
这个是简单的一组数据,也可以画多组数据
详情请参考:
多组柱状图
边栏推荐
- FRP intranet penetration, reverse proxy
- Activity的生命周期和启动模式详解
- 在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
- China carbon disulfide industry research and investment strategy report (2022 Edition)
- ShenYu 网关开发:在本地启用运行
- PHP实现敏感词过滤系统「建议收藏」
- 6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
- 判断链表是否是回文链表
- 中国冰淇淋市场深度评估及发展趋势预测报告(2022版)
- Mysql database - Advanced SQL statement (2)
猜你喜欢

Transition technology from IPv4 to IPv6

SQL question brushing 627 Change gender

Machine learning 11 clustering, outlier discrimination

Pytest learning notes (13) -allure of allure Description () and @allure title()

换掉UUID,NanoID更快更安全!

How wild are hackers' ways of making money? CTF reverse entry Guide

Detailed explanation of activity life cycle and startup mode

Iommu/smmuv3 code analysis (10) page table operation

字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化

Oom caused by improper use of multithreading
随机推荐
【flask入门系列】Cookie与Session
SQL question brushing 627 Change gender
Template Engine Velocity Foundation
Vulnhub range hacker_ Kid-v1.0.1
How wild are hackers' ways of making money? CTF reverse entry Guide
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
vulnhub靶场-hacksudo - Thor
中国茂金属聚乙烯(mPE)行业研究报告(2022版)
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
换掉UUID,NanoID更快更安全!
如何写出好代码 — 防御式编程指南
AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
Is the securities account given by the head teacher of goucai school safe? Can I open an account?
Hidden Markov model (HMM): model parameter estimation
The difference between the lazy mode of singleton mode and the evil mode
mysql -- explain性能优化
Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
【Kotlin】高阶函数介绍
LeetCode中等题之TinyURL 的加密与解密
Shenyu gateway development: enable and run locally