Note
Go to the end to download the full example code.
Simple Line Animation#
Example showing animation with lines.
/home/runner/work/fastplotlib/fastplotlib/fastplotlib/graphics/_features/_base.py:18: UserWarning: casting float64 array to float32
warn(f"casting {array.dtype} array to float32")
# test_example = false
import fastplotlib as fpl
import numpy as np
# generate some data
start, stop = 0, 2 * np.pi
increment = (2 * np.pi) / 50
# make a simple sine wave
xs = np.linspace(start, stop, 100)
ys = np.sin(xs)
figure = fpl.Figure(size=(700, 560))
# plot the image data
sine = figure[0, 0].add_line(ys, name="sine", colors="r")
# increment along the x-axis on each render loop :D
def update_line(subplot):
global increment, start, stop
xs = np.linspace(start + increment, stop + increment, 100)
ys = np.sin(xs)
start += increment
stop += increment
# change only the y-axis values of the line
subplot["sine"].data[:, 1] = ys
figure[0, 0].add_animations(update_line)
figure.show(maintain_aspect=False)
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
# please see our docs for using fastplotlib interactively in ipython and jupyter
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()
Total running time of the script: (0 minutes 5.474 seconds)