I want to know why it will be very slow when I use matplotlib to draw lines? How to fix it?
Belows are the demo code. It used plot() to draw a line between two randomly generated points.
On my computer, 'END=100/200/500' results 'FPS=36.9/28.6/20'. I need to endless draw lines and it will get worse while time being. How to solve it? Thanks!
import numpy as np
import matplotlib.pyplot as plt
import time
def draw_demo():
x = 100
plt.axis([0, x, 0, 1])
plt.ion()
last = 50
TIME = 5
END = 1000
time_start = time.time()
for i in range(0, END):
random_num = np.random.random()
if i > 70:
plt.axis([x - 100, x + 1, 0, 1])
x += 1
plt.plot([i, i + 1], [last, random_num])
last = random_num
plt.pause(0.0001)
print ('FPS:', END/(time.time()-time_start))
raw_input()
if __name__ == '__main__':
draw_demo()
def draw_demo2():intodef draw_demo():.