# import matplotlib        # only mac, if plotting doesn't work otherwise
# matplotlib.use("TkAgg")  # only mac, if plotting doesn't work otherwise

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation # IKKE PENSUM!

fig, ax = plt.subplots()
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)

xdata, ydata = [], []
line, = plt.plot([], [], '-')

def update(frame):
    global xdata, ydata

    xdata.append(np.cos(3*frame))
    ydata.append(np.sin(2*frame))

    xdata = xdata[-50:]
    ydata = ydata[-50:]

    line.set_data(xdata, ydata)
    return line,

ani = FuncAnimation(
    fig,
    update,
    frames=np.linspace(0, 4*np.pi, 256),
    interval=25,
    repeat=False,
    blit=True,
)

#with open('sine.html','w') as f:
#    f.write(ani.to_html5_video())

#ani.save('sine.mp4')

plt.show()