When I try this on my computer at home, it works, but not on my computer at work. Here is the code
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import sys
import multiprocessing
def update_line(num, gen, line):
data = gen.vals_queue.get()
data = np.array(data)
line.set_data(data[..., :num])
return line,
class Generator(multiprocessing.Process):
def __init__(self):
self.vals = [[], []]
super(Generator, self).__init__()
self.vals_queue = multiprocessing.Queue()
def run(self):
while True:
self.vals[0].append(np.random.rand())
self.vals[1].append(np.random.rand())
self.vals_queue.put(self.vals)
if __name__ == '__main__':
gen = Generator()
gen.start()
fig1 = plt.figure()
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
print 11111111111111
sys.stdout.flush()
line_ani = animation.FuncAnimation(fig1, update_line, frames=None, fargs=(gen, l),
interval=50, blit=True, repeat=False)
print 222222222222222222222222
sys.stdout.flush()
plt.show()
print 3333333333333333333333333
sys.stdout.flush()
And the conclusion that I see is
11111111111111
222222222222222222222222
3333333333333333333333333
The application does not exit, it just freezes, but the numbers do not appear. I run it from a Linux terminal. My version of matplotlib is matplotlib-2.0.0-1.x86_64
Also, I have this at work (problematic)
CentOS Linux release 7.2.1511 (Core)
echo $SHELL
/bin/bash
echo $BASH_VERSION
4.2.46(1)-release
Python 2.7.12
source
share