资源简介
python实现可暂停的动态曲线绘制,横纵坐标从上一个点到当前点,同时保存数据到文件中
代码片段和文件信息
# -*- coding=UTF-8 -*-
# 纵坐标、横坐标从上一个点到当前点
import sys
import numpy
from PyQt5 import QtWidgets
import threading
import matplotlib.ticker as ticker
from datetime import datetime
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as NavigationToolbar
from matplotlib.dates import date2num
import numpy as np
from matplotlib.figure import Figure
import os
import csv
import time
class MplCanvas(FigureCanvas):
def __init__(self):
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
FigureCanvas.__init__(self self.fig)
self.curveObj = None
def plot(self datax datay):
if self.curveObj is None:
self.curveObj = self.ax.plot_date(np.array(datax) np.array(datay) ‘b-‘)
else:
self.curveObj.set_data(np.array(datax) np.array(datay))
if len(datax) > 1:
self.ax.set_xlim(datax[-2] datax[-1])
else:
self.ax.set_xlim(datax[0] datax[-1])
# 这是纵坐标轴的范围,可根据需要自行修改
if len(datay) > 1:
self.ax.set_ylim(datay[-2] datay[-1])
else:
self.ax.set_ylim(datay[0] datay[-1])
self.ax.yaxis.set_major_formatter(ticker.FormatStrFormatter(‘%.6f‘))
xticklabels = self.ax.xaxis.get_ticklabels()
for xtick in xticklabels:
xtick.set_rotation(25)
yticklabels = self.ax.yaxis.get_ticklabels()
for ytick in yticklabels:
ytick.set_rotation(1.0)
self.draw()
class Window(QtWidgets.QWidget):
flag = 1
count = 1
def __init__(self parent=None):
super().__init__(parent)
self.canvas = MplCanvas()
self.toolbar = NavigationToolbar(self.canvas self)
# Just some button
self.button1 = QtWidgets.QPushButton(‘StartPlot‘)
self.button1.clicked.connect(self.startplot)
self.button2 = QtWidgets.QPushButton(‘Zoom‘)
self.button2.clicked.connect(self.zoom)
self.button3 = QtWidgets.QPushButton(‘Pan‘)
self.button3.clicked.connect(self.pan)
self.button4 = QtWidgets.QPushButton(‘Home‘)
self.button4.clicked.connect(self.home)
self.button5 = QtWidgets.QPushButton(‘Save‘)
self.button5.clicked.connect(self.save)
self.button6 = QtWidgets.QPushButton(‘Clear‘)
self.button6.clicked.connect(self.clear)
self.button7 = QtWidgets.QPushButton(‘StopPlot‘)
self.button7.clicked.connect(self.stopplot)
# set the layout
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
btnlayout = QtWidgets.QHBoxLayout()
btnlayout.addWidget(self.button1)
btnla
- 上一篇:使用单目摄像头测量距离
- 下一篇:人脸检测python源代码
相关资源
- 人脸检测python源代码
- python2048游戏源代码
- 机器学习-python处理UCI鲍鱼数据集.ra
- python带基因元胞自动机代码
- python-web系统实时监控
- numpy-1.17.0+mkl-cp37-cp37m-win_amd64.whl百度云
- 四行Python代码实现将word文件转换为
- python评分卡模型数据源
- 传智播客 python基础班 + 就业班 + 课件
- python实现简易3D方块动画
- 基于PYTHON+OPENCV的SIFT SURF图像特征匹配
- python总结
- boost.python 动态编译库
- 高斯投影正反算Python源码
- python xlutils
- Python3网络爬虫实战思维导图
- ros_arduino_python 调通版
- 数据挖掘十大算法源代码Python)
- XModem -发送端源代码Python语言实现
- pytracking/pytracking/evaluation/tracker.py
- Python爬取教务系统课程表
- 元胞自动机模拟交通道路_Python
- Python二级考试试题.zip
- python实现扫描线填充算法,可以画凹
- python3 包装的httpclient,支持session
- python日期时间运算
- python实现的ping工具
- Python简版聊天室代码
- Flask-login
- 矩阵分解在MovieLens上的Python实现
评论
共有 条评论