<div dir="ltr"><p style="margin-bottom:0cm;line-height:100%">Dear matplot users,</p>
<p style="margin-bottom:0cm;line-height:100%"> I have installed
Ubuntu 18 on my computer and Matplotlib, I use it to graph position
vs. time of moving objects by serial data.
</p>
<p style="margin-bottom:0cm;line-height:100%">The python script is
the following:</p>
<p style="margin-bottom:0cm;line-height:100%"><br>
</p>
<p style="margin-bottom:0cm;line-height:100%">import matplotlib</p>
<p style="margin-bottom:0cm;line-height:100%">matplotlib.use("Qt5Agg")</p>
<p style="margin-bottom:0cm;line-height:100%">import numpy as np</p>
<p style="margin-bottom:0cm;line-height:100%">import
matplotlib.pyplot as plt</p>
<p style="margin-bottom:0cm;line-height:100%">import
matplotlib.animation as animation</p>
<p style="margin-bottom:0cm;line-height:100%">from time import
sleep</p>
<p style="margin-bottom:0cm;line-height:100%">import serial</p>
<p style="margin-bottom:0cm;line-height:100%">import time</p>
<p style="margin-bottom:0cm;line-height:100%">fine="c"</p>
<p style="margin-bottom:0cm;line-height:100%">pre="ciao"</p>
<p style="margin-bottom:0cm;line-height:100%">while (fine != "f"):</p>
<p style="margin-bottom:0cm;line-height:100%"> raw_input("\n\n\n
Premi Enter per far partire la registrazione dei dati")</p>
<p style="margin-bottom:0cm;line-height:100%"> xdata, ydata = [],
[]</p>
<p style="margin-bottom:0cm;line-height:100%"> ser =
serial.Serial('/dev/ttyACM0', 9600)</p>
<p style="margin-bottom:0cm;line-height:100%"> while (False):</p>
<p style="margin-bottom:0cm;line-height:100%"> pre=ser.readline()</p>
<p style="margin-bottom:0cm;line-height:100%"> pre=ser.readline()</p>
<p style="margin-bottom:0cm;line-height:100%"> prec = float(pre)</p>
<p style="margin-bottom:0cm;line-height:100%"> y=prec</p>
<p style="margin-bottom:0cm;line-height:100%"> fig, ax =
plt.subplots()</p>
<p style="margin-bottom:0cm;line-height:100%"> line, = ax.plot([],
[], lw=2)</p>
<p style="margin-bottom:0cm;line-height:100%"> ax.set_ylim(0, 90)</p>
<p style="margin-bottom:0cm;line-height:100%"> ax.set_xlim(0, 10)</p>
<p style="margin-bottom:0cm;line-height:100%"> ax.grid()</p>
<p style="margin-bottom:0cm;line-height:100%"> def data_gen():</p>
<p style="margin-bottom:0cm;line-height:100%"> t=0
</p>
<p style="margin-bottom:0cm;line-height:100%"> y=0</p>
<p style="margin-bottom:0cm;line-height:100%"> cnt=0</p>
<p style="margin-bottom:0cm;line-height:100%"> p=0</p>
<p style="margin-bottom:0cm;line-height:100%"> a =
ser.readline()</p>
<p style="margin-bottom:0cm;line-height:100%"> while (True)&(t
< 10):</p>
<p style="margin-bottom:0cm;line-height:100%"> a =
ser.readline()</p>
<p style="margin-bottom:0cm;line-height:100%"> y =
float(a)</p>
<p style="margin-bottom:0cm;line-height:100%"> if (y !=
0) :</p>
<p style="margin-bottom:0cm;line-height:100%"> t =
(time.time() - start)</p>
<p style="margin-bottom:0cm;line-height:100%"> t =
float(t)</p>
<p style="margin-bottom:0cm;line-height:100%"> yield
t, y</p>
<p style="margin-bottom:0cm;line-height:100%"> def run(data):</p>
<p style="margin-bottom:0cm;line-height:100%"> t,y = data</p>
<p style="margin-bottom:0cm;line-height:100%"> xdata.append(t)</p>
<p style="margin-bottom:0cm;line-height:100%"> ydata.append(y)</p>
<p style="margin-bottom:0cm;line-height:100%">
ax.figure.canvas.draw()</p>
<p style="margin-bottom:0cm;line-height:100%">
line.set_data(xdata, ydata)</p>
<p style="margin-bottom:0cm;line-height:100%"> return line,</p>
<p style="margin-bottom:0cm;line-height:100%"> data_gen.t = 0</p>
<p style="margin-bottom:0cm;line-height:100%"> while (abs(y-prec)
< 2):</p>
<p style="margin-bottom:0cm;line-height:100%"> if True:</p>
<p style="margin-bottom:0cm;line-height:100%"> a =
ser.readline()</p>
<p style="margin-bottom:0cm;line-height:100%"> y =
float(a)</p>
<p style="margin-bottom:0cm;line-height:100%"> start = time.time()</p>
<p style="margin-bottom:0cm;line-height:100%"> ani =
animation.FuncAnimation(fig, run, data_gen, blit=True,
interval=5,repeat=False)</p>
<p style="margin-bottom:0cm;line-height:100%"> plt.show()</p>
<p style="margin-bottom:0cm;line-height:100%"> stop =0</p>
<p style="margin-bottom:0cm;line-height:100%">
fine=raw_input("Premi f per finire :")</p>
<p style="margin-bottom:0cm;line-height:100%"><br>
</p>
<p style="margin-bottom:0cm;line-height:100%">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.</p>
<p style="margin-bottom:0cm;line-height:100%">Can you help me?</p></div>