I listen with serial port to some data. I display these values in a tkinter output and a dashboard done in pygame. everything works great.
now I tried to integrate a plotter window with pyplot.the user can choose 2 value of 6 values. after 1-2 minutes the plotter slows down, I think the plotter hold the old values of the graph somewhere. how can I handle this in a better was.
import matplotlib.pyplot as plt
the init
def initPlotter():
global showPlotterFlag
global lastPlotterChoice
global fevent
global fig
global ax1, ax2
global start
start = time.time()
plt.style.use('bmh')
fig, (ax1, ax2) = plt.subplots(2)
fig.suptitle('mobile instruments plot')
plottertext = ["aaaaaaaaa", "bbbbbbbbbbbbbb",
"cccccccccc", "ddddddddd", "eeeeeee", "ffffffffff"]
plotterAxis = [[0, 5], [50, 150], [0, 6000], [0.7, 1.3], [50, 250], [8, 16]]
maxVal = 0
for i in range(6):
if lastPlotterChoice[i] == 1:
maxVal += 1
if (maxVal == 1):
#ax1.set_title(plottertext [i])
ax1.set_ylabel(plottertext [i])
ax1.set_ylim([plotterAxis[i][0], plotterAxis[i][1]])
if (maxVal == 2):
#ax2.set_title(plottertext [i])
ax2.set_ylabel(plottertext [i])
ax2.set_ylim(plotterAxis[i][0], plotterAxis[i][1])
if maxVal == 1:
ax2.set_ylabel('nicht benutzt')
fevent = plt.connect('close_event', handle_close)
plt.show(block=False)
showPlotterFlag=True
on the main loop:
def showPlotterDisplay():
global yps
global valueInArray
global valuesCurr
global ax1, ax2
global start
yps += 1
maxVal = 0
now = time.time() - start
for i in range(6):
if lastPlotterChoice[i] == 1:
maxVal += 1
if (maxVal == 1):
ax1.set_xlim([now-12, now+3])
ax1.plot(now, valueInArray[i], 'g.') # valueInArray[1] r+
if (maxVal == 2):
ax2.set_xlim([now-12, now+3])
ax2.plot(now, valueInArray[i], 'r.') # valueInArray[1] r+