欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PyQt5+QtChart繪制散點(diǎn)圖

 更新時(shí)間:2022年12月15日 14:57:16   作者:SongYuLong的博客  
QChart是一個(gè)QGraphicScene中可以顯示的QGraphicsWidget。本文將利用QtChart實(shí)現(xiàn)繪制散點(diǎn)圖,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下

PyQt5 QtChart-散點(diǎn)圖

QScatterSeries類將數(shù)據(jù)以散點(diǎn)圖顯示

import sys
import random
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QScatterSeries, QChart, QChartView, QPolarChart

class MyScatterWindow(QWidget):
    def __init__(self, parent=None):
        super(MyScatterWindow, self).__init__(parent)
        self.resize(800, 600)
        chart = QChart()
        chartView = QChartView()

        print(PYQT_VERSION_STR)

        scatter = QScatterSeries()
        for value in range(1, 500):
            scatter.append(value, random.random()*10)
            #scatter.append(QPointF(value, random.random()*10))

        scatter.setName("散點(diǎn)圖")
        scatter.setMarkerSize(8)   # 標(biāo)記大小
        # scatter.setMarkerShape(QScatterSeries.MarkerShapeRectangle) #方形標(biāo)記
        scatter.setMarkerShape(QScatterSeries.MarkerShapeCircle) # 圓形標(biāo)記
        pen = QPen()
        pen.setColor(Qt.red)
        pen.setWidth(2)
        scatter.setPen(pen)    
        
        chart.addSeries(scatter)
        chart.createDefaultAxes()

        chartView.setChart(chart)

        vbox = QVBoxLayout()
        vbox.addWidget(chartView)

        self.setLayout(vbox)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MyScatterWindow()
    win.show()
    sys.exit(app.exec_())

效果圖 

補(bǔ)充

除了散點(diǎn)圖,PytQt5和QtChart還可以繪制其他的圖表。下面是小編為大家整理的其他圖表繪制的示例代碼,需要的可以參考一下

PyQt5 QtChart-餅狀圖

QPieSeries類將數(shù)據(jù)以餅狀圖顯示

import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QPieSeries, QPieLegendMarker, QChart, QChartView

class MyPieWindow(QWidget):
    def __init__(self, parent=None):
        super(MyPieWindow, self).__init__(parent)

        chart = QChart()
        chartView = QChartView()
        pieSeries = QPieSeries()

        slice0 = pieSeries.append("鐵:%10", 1)
        pieSeries.append("鋁:%20", 2)
        pieSeries.append("銅:%70", 7)
        pieSeries.setLabelsVisible()
        pieSeries.setPieSize(0.6)
        
        slice0.setExploded() # 外伸
        slice0.setColor(QColor(255, 0, 150))

        chart.setTitle("餅狀圖")
        chart.addSeries(pieSeries)
        
        chartView.setChart(chart)
        chartView.setRenderHint(QPainter.Antialiasing)

        vbox = QVBoxLayout()
        vbox.addWidget(chartView)
        self.setLayout(vbox)

        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MyPieWindow()
    win.show()
    sys.exit(app.exec_())

PyQt5 QtChart-QLineSeries 折線圖

QLineSeries

QLineSeries類將數(shù)據(jù)序列顯示為折線圖,其核心代碼:

lineSeries = QLineSeries()
lineSeries.append(1, 3)
lineSeries.append(5, 8)

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)簽顏色
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtChart import *

import random

class MyWaveWindow(QWidget):
    def __init__(self, parent=None):
        super(MyWaveWindow, self).__init__(parent)
        self.setWindowTitle("折線圖")

        # 創(chuàng)建圖表 并設(shè)置相關(guān)參數(shù)
        chart = QChart()
        chart.setTitle("隨機(jī)折線圖")
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setAnimationDuration(1000)
        chart.setAnimationEasingCurve(QEasingCurve.InOutCirc)
        # chart.setTheme(QChart.ChartThemeBlueCerulean)
        chart.legend().show()


        # 創(chuàng)建折線數(shù)據(jù)序列
        lineSeries = QLineSeries()
        for value in range(0, 100):
            lineSeries.append(value, round(random.random()*10, 2))

            
        lineSeries.setPointsVisible(True)
        lineSeries.setPointLabelsVisible(True)
        lineSeries.setPointLabelsFormat("(@xPoint, @yPoint)")
        lineSeries.setPointLabelsFont(QFont(None, 8))
        lineSeries.setPointLabelsColor(QColor(255, 0, 0))
        chart.addSeries(lineSeries)

        # 創(chuàng)建軸坐標(biāo)
        # chart.createDefaultAxes()  # 創(chuàng)建默認(rèn)軸    
        axis_x = QValueAxis()
        axis_x.setLabelFormat("%d")
        axis_x.setMinorTickCount(3)
        axis_x.setRange(0, 100)
        chart.addAxis(axis_x, Qt.AlignBottom)
        lineSeries.attachAxis(axis_x)

        axis_y = QValueAxis()
        axis_y.setLabelFormat("%d")
        # axis_y.setTickType(QValueAxis.TicksDynamic)
        axis_y.setTickCount(20)
        axis_y.setMinorTickCount(3)
        axis_y.setRange(0, 10)
        chart.addAxis(axis_y, Qt.AlignLeft)
        lineSeries.attachAxis(axis_y)

            
        chartView = QChartView(chart)
        chartView.setRenderHint(QPainter.Antialiasing)

        layout = QVBoxLayout()
        layout.addWidget(chartView)
        self.setLayout(layout)
        self.resize(800, 600)
        

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MyWaveWindow()
    win.show()
    app.exit(app.exec_())

到此這篇關(guān)于PyQt5+QtChart繪制散點(diǎn)圖的文章就介紹到這了,更多相關(guān)PyQt5 QtChart散點(diǎn)圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家

相關(guān)文章

  • 安裝python3.7編譯器后如何正確安裝opnecv的方法詳解

    安裝python3.7編譯器后如何正確安裝opnecv的方法詳解

    這篇文章主要介紹了安裝python3.7編譯器后如何正確安裝opnecv,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-06-06
  • python遍歷路徑破解表單的示例

    python遍歷路徑破解表單的示例

    這篇文章主要介紹了python遍歷路徑破解表單的示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-11-11
  • 如何利用Python解析超大的json數(shù)據(jù)(GB級(jí)別)

    如何利用Python解析超大的json數(shù)據(jù)(GB級(jí)別)

    果不想從頭開始創(chuàng)建數(shù)據(jù)格式來存儲(chǔ)數(shù)據(jù),JSON是一個(gè)不錯(cuò)的選擇,下面這篇文章主要給大家介紹了關(guān)于如何利用Python解析超大的json數(shù)據(jù)(GB級(jí)別)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • Python探索之創(chuàng)建二叉樹

    Python探索之創(chuàng)建二叉樹

    這篇文章主要介紹了Python探索之創(chuàng)建二叉樹,Python的相關(guān)內(nèi)容,小編是初窺門徑。這里分享給大家一些簡單知識(shí),供需要的朋友參考。
    2017-10-10
  • python 在某.py文件中調(diào)用其他.py內(nèi)的函數(shù)的方法

    python 在某.py文件中調(diào)用其他.py內(nèi)的函數(shù)的方法

    這篇文章主要介紹了python 在某.py文件中調(diào)用其他.py內(nèi)的函數(shù)的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-06-06
  • 利用Python爬蟲爬取金融期貨數(shù)據(jù)的案例分析

    利用Python爬蟲爬取金融期貨數(shù)據(jù)的案例分析

    從技術(shù)角度來看,經(jīng)過一步步解析,任務(wù)是簡單的,入門requests爬蟲及入門pandas數(shù)據(jù)分析就可以完成,本文重點(diǎn)給大家介紹Python爬蟲爬取金融期貨數(shù)據(jù)的案例分析,感興趣的朋友一起看看吧
    2022-06-06
  • Python執(zhí)行流程控制詳情

    Python執(zhí)行流程控制詳情

    這篇文章主要介紹了Python執(zhí)行流程控制,流程控制即控制流程,具體指控制程序的執(zhí)行流程,而程序的執(zhí)行流程分為三種結(jié)構(gòu):順序結(jié)構(gòu)、分支結(jié)構(gòu)、循環(huán)結(jié)構(gòu),下文詳細(xì)介紹需要的小伙伴可以參考一下
    2022-04-04
  • Python scikit-learn數(shù)據(jù)預(yù)處理常見方法和步驟

    Python scikit-learn數(shù)據(jù)預(yù)處理常見方法和步驟

    數(shù)據(jù)預(yù)處理是數(shù)據(jù)準(zhǔn)備階段的一個(gè)重要環(huán)節(jié),主要目的是將原始數(shù)據(jù)轉(zhuǎn)換成適合機(jī)器學(xué)習(xí)模型使用的格式,數(shù)據(jù)預(yù)處理可以顯著提高機(jī)器學(xué)習(xí)模型的性能和準(zhǔn)確度,本文給大家介紹了Python數(shù)據(jù)預(yù)處理常見方法和步驟,需要的朋友可以參考下
    2024-05-05
  • 教你如何在Django 1.6中正確使用 Signal

    教你如何在Django 1.6中正確使用 Signal

    因?yàn)樾碌膁jango開發(fā)人員得知signal之后, 往往會(huì)很高興去使用它. 他們?cè)谀苁褂胹ignal的地方就使用signal, 并且這是他們覺得自己是django專家一樣. 然而, 像這樣編碼一段時(shí)間后, django項(xiàng)目就會(huì)變得異常復(fù)雜, 許多內(nèi)容都糾結(jié)在一起無法解開.
    2014-06-06
  • 淺談python中np.array的shape( ,)與( ,1)的區(qū)別

    淺談python中np.array的shape( ,)與( ,1)的區(qū)別

    今天小編就為大家分享一篇python中np.array的shape ( ,)與( ,1)的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06

最新評(píng)論