PyQt5+QtChart實(shí)現(xiàn)繪制曲線圖
QSplineSeries
QSplineSeries類(lèi)將數(shù)據(jù)序列顯示為曲線圖。核心代碼:
spline = QSplineSeries()
spline.append(0, 23)
spline.append(1, 56)
…
chart.addSeries(lineSeries)
常用方法
- setPointsVisible(True) :設(shè)置數(shù)據(jù)點(diǎn)顯示狀態(tài)
- setPointLabelsVisible(True):設(shè)置數(shù)據(jù)點(diǎn)標(biāo)簽顯示狀態(tài)
- setPointLabelsFormat(“(@xPoint, @yPoint)”):設(shè)置數(shù)據(jù)點(diǎn)標(biāo)簽格式
- setPointLabelsFont(QFont(None, 8)) :設(shè)置數(shù)據(jù)點(diǎn)標(biāo)簽字體
- setPointLabelsColor(QColor(255, 0,0)) :設(shè)置數(shù)據(jù)點(diǎn)標(biāo)簽顏色
實(shí)現(xiàn)代碼
import random import sys from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt from PyQt5.QtChart import QSplineSeries, QLineSeries, QChart, QChartView, QValueAxis class MySplineWindow(QWidget): def __init__(self, parent=None): super(MySplineWindow, self).__init__(parent) self.setWindowTitle("曲線圖表演示") chart = QChart() chart.setTitle("曲線圖表") chart.setAnimationDuration(1500) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setAnimationEasingCurve(QEasingCurve.OutCirc) chart.legend().show() spline = QSplineSeries() for value in range(1, 50): spline.append(value, round(random.random()*100)) spline.setName("隨機(jī)噪聲") # spline.setColor(Qt.blue) spline.setPointsVisible(True) spline.setPointLabelsVisible(True) spline.setPointLabelsFormat("(@xPoint, @yPoint)") spline.setPointLabelsFont(QFont(None, 6)) spline.setPointLabelsColor(Qt.darkBlue) chart.addSeries(spline) chart.createDefaultAxes() axis_x = QValueAxis() axis_x.setLabelFormat("%d") chart.addAxis(axis_x, Qt.AlignBottom) spline.attachAxis(axis_x) chartView = QChartView() chartView.setChart(chart) chartView.setRenderHint(QPainter.Antialiasing) vbox = QVBoxLayout() vbox.addWidget(chartView) self.setLayout(vbox) if __name__ == "__main__": app = QApplication(sys.argv) win = MySplineWindow() win.show() sys.exit(app.exec_())
效果圖
增加抗鋸齒:chartView.setRenderHint(QPainter.Antialiasing)
到此這篇關(guān)于PyQt5+QtChart實(shí)現(xiàn)繪制曲線圖的文章就介紹到這了,更多相關(guān)PyQt5 QtChart曲線圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python實(shí)現(xiàn)簡(jiǎn)單聊天室功能 可以私聊
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡(jiǎn)單聊天室功能,可以進(jìn)行私聊,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07Python實(shí)現(xiàn)感知機(jī)(PLA)算法
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)感知機(jī)(PLA)算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12使用Protocol Buffers的C語(yǔ)言拓展提速Python程序的示例
這篇文章主要介紹了使用Protocol Buffers的C語(yǔ)言拓展提速Python程序的示例,使用C拓展Python是Python編程進(jìn)階中的重要技巧,需要的朋友可以參考下2015-04-04使用python讀取CSV文件時(shí)遇到編碼問(wèn)題解決方案
這篇文章主要介紹了用python讀取CSV文件時(shí)遇到編碼問(wèn)題,本文給大家分享最優(yōu)解決方案,通過(guò)使用csvkit,它使用自動(dòng)檢測(cè)適當(dāng)?shù)木幋a和解碼,需要的朋友可以參考下2023-08-08