Been playing with plotting libraries for Python and came across matplotlib which seems to be battle tested and proven already. However I have came across a problem while creating a simple plot in a thread.
In the example bellow, Dummy class plotme method is run in a thread twice in a row, but it gets stuck/freezes in 2nd iteration. Most likely is something obvious and related to the threading itself, but I failed to spot it so far.
import matplotlib.pyplot as plt
from numpy import arange, sin, pi
import threading
class Dummy():
def plotme(self, iteration = 1):
print "%ix plotting... " % iteration,
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
#savefig("test.png") # irrelevant here
plt.close()
def threadme(self, iteration = 1):
thread_plot = threading.Thread(target=self.plotme,
args=(iteration,))
thread_plot.start()
thread_plot.join()
dummy = Dummy()
dummy.threadme(1)
dummy.threadme(2)
ax.plot(...)