以下两次调用函数时会生成两个窗口。我只想在调用两次时只有一个窗口有两行。日Thnx!
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation
from matplotlib.animation import FuncAnimation
#update function
def update_info(num, x, y, line):
line.set_data(x[:num], y[:num])
line.axes.axis([0, 10, 0, 5])
return line,
#drawing function
def drawLine(point1, point2, speed=50):
x1 = point1[0]
y1 = point1[1]
x2 = point2[0]
y2 = point2[1]
x = np.linspace(x1, y1, speed)
y = np.linspace(x2, y2, speed)
fig, ax1 = plt.subplots()
line, = ax1.plot(x, y, color='r')
anim = animation.FuncAnimation(fig, update_info, fargs=[x, y, line], interval=25)
plt.show()
drawLine((1, 3), (2, 4), 150)
drawLine((2, 4), (5, 1), 150)