国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

氣輕PyQt5 40 QChart多組柱狀圖(QBarSet)

2023-07-17 07:59 作者:氣輕  | 我要投稿

?

使用了2018年和2017年的兩組數(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 numpy as np

import sys

?

class PyQt540(QMainWindow):

??? def __init__(self):

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

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

?

??? def initUI(self):

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

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

?

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

??????? yearData = ['2018', '2017'];

??????? gdpData=np.array([[30319.98, 28014.94],

????????????????????????? [18809.64, 18549.19],

????????????????????????? [32679.87, 30632.99],

????????????????????????? [12820.40, 11715.10],

????????????????????????? [13509.15, 12603.36],

????????????????????????? [12001.52, 11037.28],

??????????????? ??????????[22859.35, 21503.15],

????????????????????????? [24221.98, 22490.06],

????????????????????????? [20363.19, 19424.73],

????????????????????????? [15342.77, 13889.39]])

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

?

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

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

??????? chart.setTitle("部分城市GDP")

??????? barSeries = QBarSeries()??????????????????????? # 豎向柱狀圖

?

??????? gdp = list(gdpData.transpose())

??????? barDict = dict.fromkeys(yearData)

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

??????????? barDict[value] = QBarSet(value)???????????? # 創(chuàng)建柱

??????????? barDict[value].append(gdp[i])?????????????? # 添加數(shù)據(jù)

??????????? barSeries.append(barDict[value])??????????? # 添加到barSeries

?

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

?

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

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

?

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

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

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

?

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

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

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

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

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

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

?

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

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

??????? chartView.setRenderHint(QPainter.Antialiasing)? # 增加抗鋸齒

???????

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

?

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

?

if __name__ == '__main__':

??? app = QApplication(sys.argv)

??? window = PyQt540()

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

?

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


氣輕PyQt5 40 QChart多組柱狀圖(QBarSet)的評論 (共 條)

分享到微博請遵守國家法律
晋宁县| 梁平县| 夏邑县| 吴忠市| 宜宾市| 永登县| 诸暨市| 焦作市| 新野县| 江西省| 邵东县| 福鼎市| 乌拉特中旗| 通州区| 泽州县| 临夏县| 平武县| 东平县| 宁城县| 日土县| 千阳县| 嘉善县| 论坛| 丰宁| 西平县| 开阳县| 敦化市| 南丰县| 抚州市| 大名县| 南涧| 宜黄县| 铅山县| 澄江县| 兰州市| 翁源县| 山丹县| 太保市| 抚松县| 北京市| 马龙县|