PyQt5+QtChart实现柱状图的绘制
作者:SongYuLong的博客 时间:2021-03-03 00:38:14
柱状图分类
QBarSeries:竖向柱状图
QPercentBarSeries:竖向百分比柱状图
QStackedBarSeries:竖向堆叠柱状图
QHorizontalBarSeries:横向柱状图
QHorizontalPercentBarSeries:横向百分比柱状图
QHorizontalStackedBarSeries:横向堆叠柱状图
实现代码
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QBarSet, QBarSeries, QChart, QChartView, QValueAxis, QBarCategoryAxis,\
QBarLegendMarker, QVBarModelMapper, QHBarModelMapper, QHorizontalBarSeries,QPercentBarSeries, \
QHorizontalPercentBarSeries, QHorizontalStackedBarSeries,QStackedBarSeries
class MyBarWindow(QWidget):
def __init__(self, parent=None):
super(MyBarWindow, self).__init__(parent)
chart = QChart()
barSeries = QBarSeries() # 竖向柱状图
# barSeries = QPercentBarSeries() # 竖向百分比柱状图
# barSeries = QHorizontalBarSeries() # 横向柱状图
# barSeries = QHorizontalPercentBarSeries() # 横向百分比柱状图
# barSeries = QStackedBarSeries() # 竖向堆叠柱状图
# barSeries = QHorizontalStackedBarSeries() # 横向堆叠柱状图
chartView = QChartView()
valueAxisY = QValueAxis()
barCategorAxisX = QBarCategoryAxis()
chart.setAnimationOptions(QChart.AllAnimations)
chart.setAnimationEasingCurve(QEasingCurve.OutBack)
set0 = QBarSet("产品1")
set1 = QBarSet("产品2")
set2 = QBarSet("产品3")
set0.append(10.12345)
set0.append(3.23)
set0.append(7)
set1.append(5)
set1.append(2)
set1.append(9)
set2.append(9)
set2.append(1)
set2.append(7)
barSeries.append(set0)
barSeries.append(set1)
barSeries.append(set2)
barSeries.setBarWidth(0.8)
barSeries.setLabelsVisible(True)
barSeries.setLabelsAngle(75.0)
barSeries.setLabelsPrecision(3)
# barSeries.setLabelsFormat("")
barCategorAxisX.append(["一季度", "二季度", "三季度"])
valueAxisY.setRange(0, 10)
chart.setTitle("柱状图表")
chart.setAxisX(barCategorAxisX)
chart.setAxisY(valueAxisY)
chart.addSeries(barSeries)
chartView.setChart(chart)
vbox = QVBoxLayout()
vbox.addWidget(chartView)
self.setLayout(vbox)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MyBarWindow()
win.show()
sys.exit(app.exec_())
效果图
竖向柱状图
竖向百分比柱状图
竖向堆叠柱状图
横向柱状图
横向百分比柱状图
横向堆叠柱状图
来源:https://blog.csdn.net/songyulong8888/article/details/128329284
标签:PyQt5,QtChart,柱状图
0
投稿
猜你喜欢
Python数据清洗&预处理入门教程
2021-08-15 20:14:24
Python3中map()、reduce()、filter()的用法详解
2024-01-03 01:27:23
Python动态语言与鸭子类型详解
2021-02-21 07:22:49
ASP 包含文件中的路径问题和使用单一数据库连接文件的解决方案
2011-04-07 10:35:00
JavaScript 组件之旅(一):分析和设计
2009-09-21 10:52:00
pytorch sampler对数据进行采样的实现
2023-02-09 20:05:40
Python生成器(Generator)详解
2022-10-05 01:14:43
Python ini配置文件示例详解
2023-08-24 09:07:36
python检测文件夹变化,并拷贝有更新的文件到对应目录的方法
2023-11-07 12:56:06
display:inline-block的深入理解
2007-05-11 17:03:00
利用Python实现Picgo图床工具
2023-10-09 16:10:45
JavaScript实现简单省市联动
2024-04-16 09:53:44
如何删除Git本地仓库和删除GitHub上的Git远程仓库Repository(推荐)
2023-01-30 16:07:59
Python3中configparser模块读写ini文件并解析配置的用法详解
2022-11-02 12:11:14
2008年情人节各网站节日Logo欣赏
2008-02-17 14:12:00
Django+Nginx+uWSGI 定时任务的实现方法
2022-11-14 16:02:57
python之pil的使用详解
2023-01-19 07:21:19
解决win10 vscode 无法激活python 虚拟环境的问题
2023-10-09 04:23:25
Go gRPC服务客户端流式RPC教程
2023-07-16 06:08:55
基于Bootstrap+jQuery.validate实现Form表单验证
2024-05-13 09:06:57