<bdo id='fC26K'></bdo><ul id='fC26K'></ul>
  • <small id='fC26K'></small><noframes id='fC26K'>

    <legend id='fC26K'><style id='fC26K'><dir id='fC26K'><q id='fC26K'></q></dir></style></legend>
    <tfoot id='fC26K'></tfoot>

        <i id='fC26K'><tr id='fC26K'><dt id='fC26K'><q id='fC26K'><span id='fC26K'><b id='fC26K'><form id='fC26K'><ins id='fC26K'></ins><ul id='fC26K'></ul><sub id='fC26K'></sub></form><legend id='fC26K'></legend><bdo id='fC26K'><pre id='fC26K'><center id='fC26K'></center></pre></bdo></b><th id='fC26K'></th></span></q></dt></tr></i><div id='fC26K'><tfoot id='fC26K'></tfoot><dl id='fC26K'><fieldset id='fC26K'></fieldset></dl></div>

      1. 在 python 中快速绘制数据

        Fast plotting data in python(在 python 中快速绘制数据)

          <small id='P9U6R'></small><noframes id='P9U6R'>

        1. <legend id='P9U6R'><style id='P9U6R'><dir id='P9U6R'><q id='P9U6R'></q></dir></style></legend>

            <tbody id='P9U6R'></tbody>
          • <i id='P9U6R'><tr id='P9U6R'><dt id='P9U6R'><q id='P9U6R'><span id='P9U6R'><b id='P9U6R'><form id='P9U6R'><ins id='P9U6R'></ins><ul id='P9U6R'></ul><sub id='P9U6R'></sub></form><legend id='P9U6R'></legend><bdo id='P9U6R'><pre id='P9U6R'><center id='P9U6R'></center></pre></bdo></b><th id='P9U6R'></th></span></q></dt></tr></i><div id='P9U6R'><tfoot id='P9U6R'></tfoot><dl id='P9U6R'><fieldset id='P9U6R'></fieldset></dl></div>

              <tfoot id='P9U6R'></tfoot>

                • <bdo id='P9U6R'></bdo><ul id='P9U6R'></ul>
                  本文介绍了在 python 中快速绘制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 arduino 绘制来自 mpu6050 imu 的数据.MPU6050 发送数据的速度比绘图快.Arduino 代码从串口提供 6 个数据,分别是 yaw、pitch、roll、ax、ay 和 az.我需要快速剧情的建议.

                  I'm trying to plot data from mpu6050 imu with arduino. MPU6050 sends data faster than plot. Arduino code gives 6 data which are yaw, pitch, roll, ax,ay and az from serial port. I need suggestions for fast plot .

                  Python 代码:

                  import serial
                  import matplotlib.pyplot as plt #import matplotlib library
                  from drawnow import * 
                  
                  ser = serial.Serial('COM9', 115200)
                  yaw = 0.0
                  pitch =0.0
                  roll =0.0
                  ax =0.0
                  ay =0.0
                  az =0.0
                  o_yaw= [0]
                  o_pitch= [0]
                  o_roll= [0]
                  o_ax= [0]
                  o_ay= [0]
                  o_az= [0]
                  plt.ion()
                  cnt=0
                  def makeFig(): 
                      plt.ylim(-1000,1000)                                 
                      plt.grid(True)
                      plt.ylabel('Magnitude')  
                      plt.plot(olculen_ax, 'ro-', label='ax') 
                      plt.plot(olculen_ay, 'bo-', label='ay')  
                      plt.plot(olculen_az, 'go-', label='az')                               
                      plt.legend()                    
                  while True:
                      incoming=ser.readline()
                      if ("hand" in incoming):
                          incoming=incoming.split(":")
                          if len(incoming)==8:
                              yaw = float(incoming[1])
                              pitch = float(incoming[2])
                              roll = float(incoming[3])
                              ax = float(incoming[4])
                              ay = float(incoming[5])
                              az = float(incoming[6])
                              print "Split works"
                      else:
                          print incoming
                      o_ax.append(ax)                    
                      o_ay.append(ay)    
                      o_az.append(az)
                      o_yaw.append(yaw)
                      o_pitch.append(pitch)
                      o_roll.append(roll)              
                  
                      drawnow(makeFig)                       
                      plt.pause(.00001)                     
                      cnt=cnt+1
                      if(cnt>50):                            
                          o_ax.pop(0)
                          o_ay.pop(0)                     
                          o_az.pop(0)
                  

                  Arduino 代码(我只是添加循环.代码源自 这个):

                  Arduino Code (I just add loop. code derived from this):

                  void loop() {
                      if (!dmpReady) return;
                      while (!mpuInterrupt && fifoCount < packetSize) {
                      }
                  
                      mpuInterrupt = false;
                      mpuIntStatus = mpu.getIntStatus();
                  
                      fifoCount = mpu.getFIFOCount();
                  
                       if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
                      mpu.resetFIFO();
                      //Serial.println(F("FIFO overflow!"));
                  } else if (mpuIntStatus & 0x02) {
                      while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
                      mpu.getFIFOBytes(fifoBuffer, packetSize);
                      fifoCount -= packetSize;
                      mpu.dmpGetQuaternion(&q, fifoBuffer);
                      mpu.dmpGetAccel(&aa, fifoBuffer);
                      mpu.dmpGetGravity(&gravity, &q);
                      mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
                      mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
                      mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
                      Serial.print("hand:");
                      Serial.print(ypr[0] * 180/M_PI);
                      Serial.print(":");
                      Serial.print(ypr[1] * 180/M_PI);
                      Serial.print(":");
                      Serial.print(ypr[2] * 180/M_PI);
                      Serial.print(":");
                      Serial.print(aaWorld.x);
                      Serial.print(":");
                      Serial.print(aaWorld.y);
                      Serial.print(":");
                      Serial.print(aaWorld.z);
                      Serial.println(":");
                  }
                  
                  }
                  

                  推荐答案

                  pyqtgraph 模块是一个很好的解决方案.它非常快速和简单.

                  The pyqtgraph module is a great solution. It is very fast and easy.

                  这是新代码:

                  from pyqtgraph.Qt import QtGui, QtCore
                  import numpy as np
                  import pyqtgraph as pg
                  from pyqtgraph.ptime import time
                  import serial
                  
                  app = QtGui.QApplication([])
                  
                  p = pg.plot()
                  p.setWindowTitle('live plot from serial')
                  curve = p.plot()
                  
                  data = [0]
                  raw=serial.Serial('COM9', 115200)
                  
                  
                  def update():
                      global curve, data
                      line = raw.readline()
                      if ("hand" in line):
                         line=line.split(":")
                         if len(line)==8:
                              data.append(float(line[4]))
                              xdata = np.array(data, dtype='float64')
                              curve.setData(xdata)
                              app.processEvents()
                  
                  timer = QtCore.QTimer()
                  timer.timeout.connect(update)
                  timer.start(0)
                  
                  if __name__ == '__main__':
                      import sys
                      if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
                          QtGui.QApplication.instance().exec_()
                  

                  这篇关于在 python 中快速绘制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                  <legend id='AmbMz'><style id='AmbMz'><dir id='AmbMz'><q id='AmbMz'></q></dir></style></legend>
                  • <bdo id='AmbMz'></bdo><ul id='AmbMz'></ul>

                      <tbody id='AmbMz'></tbody>

                    <tfoot id='AmbMz'></tfoot>

                    <small id='AmbMz'></small><noframes id='AmbMz'>

                      <i id='AmbMz'><tr id='AmbMz'><dt id='AmbMz'><q id='AmbMz'><span id='AmbMz'><b id='AmbMz'><form id='AmbMz'><ins id='AmbMz'></ins><ul id='AmbMz'></ul><sub id='AmbMz'></sub></form><legend id='AmbMz'></legend><bdo id='AmbMz'><pre id='AmbMz'><center id='AmbMz'></center></pre></bdo></b><th id='AmbMz'></th></span></q></dt></tr></i><div id='AmbMz'><tfoot id='AmbMz'></tfoot><dl id='AmbMz'><fieldset id='AmbMz'></fieldset></dl></div>