最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

氣輕PyQt5 39 QChart柱狀圖(QBarSet)

2023-07-10 08:31 作者:氣輕  | 我要投稿

?

在【氣輕Python34】采用matplotlib制作過同樣數(shù)據(jù)的柱狀圖。

?

from PyQt5.QtGui import *

from PyQt5.QtCore import *

from PyQt5.QtWidgets import *

from PyQt5.QtChart import QBarSeries, QBarSet, QChart, QChartView, QValueAxis, QBarCategoryAxis

from math import ceil

import sys

?

class PyQt539(QMainWindow):

??? def __init__(self):

??????? super().__init__()

??????? self.initUI()

?

??? def initUI(self):

??????? self.setWindowTitle("chart")

??????? self.resize(600, 400)?????????????????????????? # 設(shè)置窗口大小

?

??????? cityName = ['北京', '天津', '上海', '南京', '杭州', '青島', '廣州', '深圳', '重慶', '成都']

??????? gdpData? = [30319.98, 18809.64, 32679.87, 12820.4, 13509.15,

??????????????????? 12001.52, 22859.35, 24221.98, 20363.19, 15342.77]

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

?

??????? chart = QChart()??????????????????????????????? # 圖表組件

?

??????? pen = QPen(QColor('#8B000'),3)????????????????? # 曲線顏色

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

??????? for i, value in enumerate(gdpData):

??????????? GDPBar.append(value)

?

?

??????? barSeries = QBarSeries()

??????? barSeries.append(GDPBar)

??????? chart.addSeries(barSeries)

?

??????? axis_x = QBarCategoryAxis()??????????????? ?????# 柱狀圖坐標

??????? axis_x.append(cityName)

??????? axis_x.setLinePen(pen)????????????????????????? # 設(shè)置X軸顏色和寬度

?

??????? axis_x.setTitleText("城市")

??????? chart.addAxis(axis_x, Qt.AlignBottom)

??????? barSeries.attachAxis(axis_x)

?

??????? axis_y = QValueAxis()

??????? axis_y.setLabelFormat("%d")

??????? axis_y.setRange(0, MaxGDP)

??????? axis_y.setTitleText("億元")

??????? chart.addAxis(axis_y, Qt.AlignLeft)

??????? axis_y.setLinePen(pen)????????????????????????? # 設(shè)置Y軸顏色和寬度

??????? barSeries.attachAxis(axis_y)

?

??????? chartView = QChartView()??????????????????????? # 視圖組件

??????? chartView.setChart(chart)?????????????????????? # 顯示chart

???????

??????? self.setCentralWidget(chartView)

?

??????? self.show()

?

if __name__ == '__main__':

??? app = QApplication(sys.argv)

??? window = PyQt539()

??? sys.exit(app.exec())

?

執(zhí)行結(jié)果


氣輕PyQt5 39 QChart柱狀圖(QBarSet)的評論 (共 條)

分享到微博請遵守國家法律
南开区| 望都县| 军事| 信宜市| 营口市| 奈曼旗| 扎兰屯市| 博野县| 内黄县| 什邡市| 红安县| 浪卡子县| 桂林市| 乐业县| 松潘县| 乐安县| 昭通市| 武义县| 建德市| 庆城县| 公安县| 金华市| 江口县| 咸宁市| 山东省| 旅游| 湘乡市| 安塞县| 木兰县| 长岛县| 怀化市| 潜山县| 阿克| 信丰县| 水城县| 无极县| 竹山县| 迁安市| 永登县| 玛纳斯县| 二连浩特市|