Matplotlib animation not showing

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
+4
source share
2 answers

It is very difficult to reproduce this problem, so I will try to give some general advice and try to guess the actual root of the problem.

, virtualenvs, . requirements.txt (, ) requirements.txt, virtualenv , , . , , .

, . , :

  • - ?
  • , matplotlib? :

    import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4]) plt.ylabel('some numbers') plt.show()

  • 2 , plt.show() plt.savefig('numbers.png') , . , matplotlib. numbers.png, , - matplotlib , . , , matplotlib , , Tkinter, .

, , .

p.s. , , / :

'backend' matplotlib Python?

http://matplotlib.org/faq/usage_faq.html#what-is-a-backend

+5

, ​​ . , ,

Ubuntu/Debian OS :

                    sudo apt-get install python-matplotlib

:

                    python -m pip install -U pip setuptools
                    python -m pip install matplotlib

, .

: https://matplotlib.org/users/installing.html

0

Source: https://habr.com/ru/post/1679650/


All Articles