当前位置:网站首页>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_())
这个是简单的一组数据,也可以画多组数据
详情请参考:
多组柱状图
边栏推荐
- Please, stop painting star! This has nothing to do with patriotism!
- 【PyG】文档总结以及项目经验(持续更新
- Leetcode 77 combination -- backtracking method
- 为什么你要考虑使用Prisma
- There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
- redis -- 数据类型及操作
- 剑指 Offer II 015. 字符串中的所有变位词
- FRP intranet penetration, reverse proxy
- C語言輸入/輸出流和文件操作
- 提交review时ReviewBoard出现500错误解决方法
猜你喜欢
英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
Detailed explanation of string's trim() and substring()
Redis distributed lock
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
Iommu/smmuv3 code analysis (10) page table operation
Girls who want to do software testing look here
LeetCode中等题之TinyURL 的加密与解密
Machine learning 11 clustering, outlier discrimination
Redis 分布式鎖
Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!
随机推荐
中国氮化硅陶瓷基板行业研究与投资前景报告(2022版)
(12) About time-consuming printing
SQL question brushing 627 Change gender
Hi Fun Summer, play SQL planner with starrocks!
[kotlin] Introduction to higher-order functions
Redis 分布式鎖
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
China carbon disulfide industry research and investment strategy report (2022 Edition)
Leetcode 216 combined summation III -- backtracking method
Hidden Markov model (HMM): model parameter estimation
SQL注入漏洞(Mysql与MSSQL特性)
Integer array merge [JS]
GameFramework食用指南
China BMS battery management system Market Research Report (2022 Edition)
中国乙腈市场预测与战略咨询研究报告(2022版)
In aks, use secret in CSI driver mount key vault
C語言輸入/輸出流和文件操作
Girls who want to do software testing look here
The amazing open source animation library is not only awesome, but also small
Flux d'entrées / sorties et opérations de fichiers en langage C