气轻PyQt5 39 QChart柱状图(QBarSet)

2023-07-10 08:23:23 哔哩哔哩

在【气轻Python34】采用matplotlib制作过同样数据的柱状图。

from import *

from import *


【资料图】

from import *

from import QBarSeries, QBarSet, QChart, QChartView, QValueAxis, QBarCategoryAxis

from math import ceil

import sys

class PyQt539(QMainWindow):

def __init__(self):

super().__init__()

()

def initUI(self):

("chart")

(600, 400)                           # 设置窗口大小

cityName = ['北京', '天津', '上海', '南京', '杭州', '青岛', '广州', '深圳', '重庆', '成都']

gdpData  = [, , , , ,

, , , , ]

MaxGDP = ceil(max(gdpData)/9)*10

chart = QChart()                                # 图表组件

pen = QPen(QColor('#8B000'),3)                  # 曲线颜色

GDPBar = QBarSet('2018年部分城市GDP')

for i, value in enumerate(gdpData):

(value)

barSeries = QBarSeries()

(GDPBar)

(barSeries)

axis_x = QBarCategoryAxis()                     # 柱状图坐标

axis_(cityName)

axis_(pen)                          # 设置X轴颜色和宽度

axis_("城市")

(axis_x, )

(axis_x)

axis_y = QValueAxis()

axis_("%d")

axis_(0, MaxGDP)

axis_("亿元")

(axis_y, )

axis_(pen)                          # 设置Y轴颜色和宽度

(axis_y)

chartView = QChartView()                        # 视图组件

(chart)                       # 显示chart

(chartView)

()

if __name__ == '__main__':

app = QApplication()

window = PyQt539()

(())

执行结果

标签:

相关文章
最新发布
精彩图文
精彩推送

Copyright @  2015-2018 北极it网版权所有  备案号:浙ICP备2022016517号-19   联系邮箱:514 676 113@qq.com