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

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

氣輕PyQt5 42 QChart動(dòng)畫(huà)模式(Animation)

2023-07-27 07:45 作者:氣輕  | 我要投稿

?

from PyQt5.QtGui import *

from PyQt5.QtCore import *

from PyQt5.QtWidgets import *

from PyQt5.QtChart import QSplineSeries, QLineSeries, QChart, QChartView, QValueAxis, QBarCategoryAxis

import numpy as np

from math import ceil, floor

import sys

?

class PyQt538(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

??????? MinGDP = floor(gdpData.min()/10)*8

?

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

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

?

??????? chart.setAnimationOptions(QChart.SeriesAnimations)

??????? chart.setAnimationDuration(500)???????????????? # 動(dòng)畫(huà)持續(xù)時(shí)間msecs

??????? chart.setAnimationEasingCurve(QEasingCurve.OutCirc)

??????? chart.legend().show()

?

??????? spline18 = self.addSpline(gdpData[:,0],'#FFA500','2018');

??????? spline17 = self.addSpline(gdpData[:,1],'#00A5FF','2017');

?

??????? chart.addSeries(spline18)?????????????????????? # 添加Series

??????? chart.addSeries(spline17)?????????????????????? # 添加Series

?

??????? penx = QPen(QColor(0x1E90FF))?????????????????? # X軸顏色

??????? penx.setWidth(2)??????????????????????????????? # X軸寬度

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

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

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

??????? axis_x.setRange(cityName[0], cityName[-1])

?

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

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

??????? spline18.attachAxis(axis_x)

??????? spline17.attachAxis(axis_x)

?

??????? peny = QPen(QColor(0x8B7500))?????????????????? # Y軸顏色

??????? peny.setWidth(2)??????????????????????????????? # Y軸寬度

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

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

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

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

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

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

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

??????? spline18.attachAxis(axis_y)

??????? spline17.attachAxis(axis_y)

?

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

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

???????

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

?

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

?

??? def addSpline(self,points,color,lineName):

?

??????? pens = QPen(QColor(color),3)??????????????????? # 曲線顏色

??????? spline = QSplineSeries()??????????????????????? # 樣條曲線

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

??????????? spline.append(i, value)

?

??????? spline.setName(lineName)

??????? spline.setColor(Qt.blue)

??????? spline.setPointsVisible(True)?????????????????? # 數(shù)據(jù)點(diǎn)可視

??????? spline.setPen(pens)???????????????????????????? # 設(shè)置曲線顏色和寬度

?

??????? return spline

?

if __name__ == '__main__':

??? app = QApplication(sys.argv)

??? window = PyQt538()

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


氣輕PyQt5 42 QChart動(dòng)畫(huà)模式(Animation)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
温泉县| 兴安盟| 和田县| 随州市| 大城县| 雷波县| 巴林右旗| 恩施市| 饶阳县| 霍州市| 陇川县| 商南县| 潞城市| 民县| 安龙县| 家居| 上虞市| 吐鲁番市| 阿合奇县| 丹棱县| 子洲县| 长白| 疏附县| 淳安县| 南安市| 汨罗市| 高邑县| 抚远县| 托克逊县| 农安县| 延川县| 濮阳县| 吴忠市| 修水县| 汉中市| 潞城市| 科尔| 朔州市| 靖江市| 安乡县| 普定县|