Help request serila data plot, Ubuntu 18

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Help request serila data plot, Ubuntu 18

Animatore. TRPS03000X

Dear matplot users,

I have installed Ubuntu 18 on my computer and Matplotlib, I use it to graph position vs. time of moving objects by serial data.

The python script is the following:


import matplotlib

matplotlib.use("Qt5Agg")

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as animation

from time import sleep

import serial

import time

fine="c"

pre="ciao"

while (fine != "f"):

     raw_input("\n\n\n Premi Enter per far partire la registrazione dei dati")

     xdata, ydata = [], []

     ser = serial.Serial('/dev/ttyACM0', 9600)

     while (False):

          pre=ser.readline()

     pre=ser.readline()

     prec = float(pre)

     y=prec

     fig, ax = plt.subplots()

     line, = ax.plot([], [], lw=2)

     ax.set_ylim(0, 90)

     ax.set_xlim(0, 10)

     ax.grid()

     def data_gen():

         t=0

         y=0

        cnt=0

        p=0

        a = ser.readline()

        while (True)&(t < 10):

            a = ser.readline()

            y = float(a)

            if (y != 0) :

                t = (time.time() - start)

                t = float(t)

                yield t, y

     def run(data):

         t,y = data

        xdata.append(t)

        ydata.append(y)

        ax.figure.canvas.draw()

        line.set_data(xdata, ydata)

       return line,

data_gen.t = 0

while (abs(y-prec) < 2):

    if True:

         a = ser.readline()

         y = float(a)

         start = time.time()

 ani = animation.FuncAnimation(fig, run, data_gen, blit=True, interval=5,repeat=False)

 plt.show()

 stop =0

fine=raw_input("Premi f per finire :")


It works fine, but after the plotting (10 seconds), there is a problem, I cannnot use the tools of the matplot window, i.e. when I try to zoom, after selecting the area, the plot desappear.

Can you help me?


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users