0

The following generates two windows when calling the function twice. I want it just one window with two lines when calling twice. 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)

0 Answers0