Basically I want to pause the live plot that I have setup here:
import serial
import numpy as np
from matplotlib import pyplot as plt
ser = serial.Serial('/dev/tty.usbmodemfa131', 9600)
#Setting up the animated plot
plt.ion() # set plot to animated
fig = plt.figure()
ydata = [0] * 100
ax1=plt.axes()
# make plot
line, = plt.plot(ydata)
plt.ylim([24,29])
#Starting data collection
while True:
rawData = ser.readline().rstrip()
x = len(rawData)
#print(floatData)
if len(rawData) <= 6:
try:
data = float(rawData)
if data <= 100:
ydata.append(data)
del ydata[0]
line.set_xdata(np.arange(len(ydata)))
line.set_ydata(ydata) # update the data
plt.draw() # update the plot
except ValueError:
print "Not a float"
I am wanting to pause the plot in the figure but I can't figure out how to work with the figure at all as the data is streaming.
So a good solution to your problem would be to use a thread to run the plotting window and have control performed through the main thread. This could be implemented like so:
This should give you a command line interface like:
Where any of the following statements should control the plotter