当前位置:网站首页>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_())
这个是简单的一组数据,也可以画多组数据
详情请参考:
多组柱状图
边栏推荐
- [Supplément linguistique c] déterminer quel jour est demain (date de demain)
- 【C补充】【字符串】按日期排序显示一个月的日程
- What is the effect of choosing game shield safely in the game industry?
- 巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
- 字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
- Computed property “xxx“ was assigned to but it has no setter.
- sql刷题584. 寻找用户推荐人
- 剑指 Offer II 015. 字符串中的所有变位词
- Vulnhub range hacksudo Thor
- 英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
猜你喜欢

Soft test network engineer full truth simulation question (including answer and analysis)

英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放

String的trim()和substring()详解

SQL question brushing 627 Change gender

Basic usage of Frida

Redis6.0 new features

软件工程导论——第六章——详细设计

GameFramework食用指南

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

Template Engine Velocity Foundation
随机推荐
Concatenate strings to get the result with the smallest dictionary order
C語言輸入/輸出流和文件操作
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
SQL question brushing 586 Customers with the most orders
The difference between the lazy mode of singleton mode and the evil mode
官宣!香港科技大学(广州)获批!
Hi Fun Summer, play SQL planner with starrocks!
Leetcode records - sort -215, 347, 451, 75
【PyG】文档总结以及项目经验(持续更新
中国生物降解塑料市场预测与投资战略报告(2022版)
【Kotlin】高阶函数介绍
sql刷题627. 变更性别
Soft test network engineer full truth simulation question (including answer and analysis)
GameFramework食用指南
Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!
《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
What are the differences between PHP and DW
Basic usage of Frida
Shenyu gateway development: enable and run locally
Girls who want to do software testing look here