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

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

氣輕PyQt5 41 QChart水平柱狀圖(QBarSet)

2023-07-24 07:15 作者:氣輕  | 我要投稿

?

from PyQt5.QtGui import *

from PyQt5.QtCore import *

from PyQt5.QtWidgets import *

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

from math import ceil

import numpy as np

import sys

?

class PyQt541(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 = QHorizontalBarSeries()

?

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

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

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

??????????? barDict[value] = QBarSet(value)

??????????? barDict[value].append(gdp[i])

??????????? barSeries.append(barDict[value])

?

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

?

??????? axis_x = QValueAxis()

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

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

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

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

?

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

??????? axis_y.append(cityName)

?

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

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

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

?

??????? 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 = PyQt541()

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

?

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


氣輕PyQt5 41 QChart水平柱狀圖(QBarSet)的評論 (共 條)

分享到微博請遵守國家法律
扶沟县| 苗栗县| 田阳县| 蓬莱市| 祥云县| 永德县| 海南省| 桓台县| 浙江省| 霍州市| 屏东市| 运城市| 临泉县| 临泽县| 泾阳县| 将乐县| 镇安县| 紫金县| 图们市| 萨嘎县| 嘉禾县| 通城县| 沅江市| 虎林市| 汶川县| 深水埗区| 涡阳县| 隆德县| 松溪县| 龙海市| 涿鹿县| 望谟县| 沭阳县| 宽甸| 阜城县| 中宁县| 晋宁县| 鄂温| 宣恩县| 荣成市| 长乐市|