文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

PyQt5+QtChart实现绘制极坐标图

2022-12-16 12:00

关注

散点极坐标图

import sys
import random
import math

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

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

        # 创建图表
        polarChart = QPolarChart()
        chartView = QChartView()

        # 创建Series
        scatterSeries = QScatterSeries()

        # 添加数据
        for value in range(1, 50):
            scatterSeries.append(value, random.random()*10)
            #scatterSeries.append(QPointF(value, random.random()*10))
        
        scatterSeries.setMarkerSize(10)
        scatterSeries.setColor(Qt.red)
        scatterSeries.setBorderColor(Qt.yellow)
        scatterSeries.setMarkerShape(QScatterSeries.MarkerShapeCircle)  # 圆形标记
        # scatterSeries.setMarkerShape(QScatterSeries.MarkerShapeRectangle) # 方形标记        
        scatterSeries.setName("星位图")

        polarChart.addSeries(scatterSeries)
        polarChart.setContentsMargins(0, 0, 0, 0)
        polarChart.setTheme(QChart.ChartThemeBlueCerulean)
        # polarChart.createDefaultAxes()


        # 设置 角向轴
        angularAxis = QValueAxis()
        angularAxis.setTickCount(9)
        angularAxis.setLabelFormat("%.2f")
        angularAxis.setShadesVisible(True)
        angularAxis.setShadesBrush(QBrush(QColor(230, 230, 255)))
        polarChart.addAxis(angularAxis, QPolarChart.PolarOrientationAngular)
        angularAxis.setRange(0, 20) # 必须设置范围,否则图表无法显示

        # 设置 径向轴
        radialAxis = QValueAxis()
        radialAxis.setTickCount(5)
        radialAxis.setLabelFormat("%d")
        polarChart.addAxis(radialAxis, QPolarChart.PolarOrientationRadial)
        radialAxis.setRange(0, 10)
        
        chartView.setChart(polarChart)
        chartView.setFocusPolicy(Qt.NoFocus)
        chartView.setRenderHint(QPainter.Antialiasing)

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

        # polarChart.zoomOut()
        # polarChart.zoomIn()
        # polarChart.scroll(-1.0, 0)
        # polarChart.scroll(1.0, 0)
        # polarChart.scroll(0, 1.0)
        # polarChart.scroll(0, -1.0)

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

折线极坐标图

import sys
import random
import math

from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QLineSeries, QPolarChart, QChart, QChartView, QValueAxis

class MyPolarWindow(QWidget):
    def __init__(self, parent=None):
        super(MyPolarWindow, self).__init__(parent)
        self.setWindowTitle("散点极坐标图")
        # 创建图表
        polarChart = QPolarChart()
        chartView = QChartView()

        # 创建Series
        scatterSeries = QLineSeries()

        # 添加数据
        for value in range(1, 50):
            scatterSeries.append(value, random.random()*10)
            #scatterSeries.append(QPointF(value, random.random()*10))
        

        scatterSeries.setName("折线极坐标图")

        polarChart.addSeries(scatterSeries)
        polarChart.setContentsMargins(0, 0, 0, 0)
        polarChart.setTheme(QChart.ChartThemeBlueCerulean)
        # polarChart.createDefaultAxes()


        # 设置 角向轴
        angularAxis = QValueAxis()
        angularAxis.setTickCount(9)
        angularAxis.setLabelFormat("%.2f")
        angularAxis.setShadesVisible(True)
        angularAxis.setShadesBrush(QBrush(QColor(230, 230, 255)))
        polarChart.addAxis(angularAxis, QPolarChart.PolarOrientationAngular)
        angularAxis.setRange(0, 20) # 必须设置范围,否则图表无法显示

        # 设置 径向轴
        radialAxis = QValueAxis()
        radialAxis.setTickCount(5)
        radialAxis.setLabelFormat("%d")
        polarChart.addAxis(radialAxis, QPolarChart.PolarOrientationRadial)
        radialAxis.setRange(0, 10)
        
        chartView.setChart(polarChart)
        chartView.setFocusPolicy(Qt.NoFocus)
        chartView.setRenderHint(QPainter.Antialiasing)

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

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

曲线极坐标图

import sys
import random
import math

from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QSplineSeries, QPolarChart, QChart, QChartView, QValueAxis

class MyPolarWindow(QWidget):
    def __init__(self, parent=None):
        super(MyPolarWindow, self).__init__(parent)
        self.setWindowTitle("散点极坐标图")
        # 创建图表
        polarChart = QPolarChart()
        chartView = QChartView()

        # 创建Series
        scatterSeries = QSplineSeries()

        # 添加数据
        for value in range(1, 50):
            scatterSeries.append(value, random.random()*10)
            #scatterSeries.append(QPointF(value, random.random()*10))
        

        scatterSeries.setName("曲线极坐标图")

        polarChart.addSeries(scatterSeries)
        polarChart.setContentsMargins(0, 0, 0, 0)
        polarChart.setTheme(QChart.ChartThemeBlueCerulean)
        # polarChart.createDefaultAxes()


        # 设置 角向轴
        angularAxis = QValueAxis()
        angularAxis.setTickCount(9)
        angularAxis.setLabelFormat("%.2f")
        angularAxis.setShadesVisible(True)
        angularAxis.setShadesBrush(QBrush(QColor(230, 230, 255)))
        polarChart.addAxis(angularAxis, QPolarChart.PolarOrientationAngular)
        angularAxis.setRange(0, 20) # 必须设置范围,否则图表无法显示

        # 设置 径向轴
        radialAxis = QValueAxis()
        radialAxis.setTickCount(5)
        radialAxis.setLabelFormat("%d")
        polarChart.addAxis(radialAxis, QPolarChart.PolarOrientationRadial)
        radialAxis.setRange(0, 10)
        
        chartView.setChart(polarChart)
        chartView.setFocusPolicy(Qt.NoFocus)
        chartView.setRenderHint(QPainter.Antialiasing)

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

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

区域极坐标图

import sys
import random
import math

from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtChart import QLineSeries, QAreaSeries, QPolarChart, QChart, QChartView, QValueAxis

class MyPolarWindow(QWidget):
    def __init__(self, parent=None):
        super(MyPolarWindow, self).__init__(parent)
        self.setWindowTitle("区域极坐标图")
        # 创建图表
        polarChart = QPolarChart()
        chartView = QChartView()

         # 创建Series
        series0 = QLineSeries()
        series1 = QLineSeries()

        # 添加数据
        series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) \
        << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5)
        series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) \
        << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3)

        # 创建区域图
        area = QAreaSeries(series0, series1)
        area.setName("折线极坐标图")

        polarChart.addSeries(area)
        polarChart.setContentsMargins(0, 0, 0, 0)
        polarChart.setTheme(QChart.ChartThemeBlueCerulean)
        # polarChart.createDefaultAxes()


        # 设置 角向轴
        angularAxis = QValueAxis()
        angularAxis.setTickCount(9)
        angularAxis.setLabelFormat("%.2f")
        angularAxis.setShadesVisible(True)
        angularAxis.setShadesBrush(QBrush(QColor(230, 230, 255)))
        polarChart.addAxis(angularAxis, QPolarChart.PolarOrientationAngular)
        angularAxis.setRange(0, 50) # 必须设置范围,否则图表无法显示

        # 设置 径向轴
        radialAxis = QValueAxis()
        radialAxis.setTickCount(5)
        radialAxis.setLabelFormat("%d")
        polarChart.addAxis(radialAxis, QPolarChart.PolarOrientationRadial)
        radialAxis.setRange(0, 20)
        
        chartView.setChart(polarChart)
        chartView.setFocusPolicy(Qt.NoFocus)
        chartView.setRenderHint(QPainter.Antialiasing)

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

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

以上就是PyQt5+QtChart实现绘制极坐标图的详细内容,更多关于PyQt5 QtChart极坐标图的资料请关注编程网其它相关文章!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯