Note
Go to the end to download the full example code.
Scatter sizes animation#
Animate scatter sizes
/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 numpy as np
import fastplotlib as fpl
xs = np.linspace(0, 10 * np.pi, 1_000)
# sine wave
ys = np.sin(xs)
data = np.column_stack([xs, ys])
sizes = np.abs(ys) * 5
figure = fpl.Figure(size=(700, 560))
figure[0, 0].add_scatter(data, sizes=sizes, name="sine")
i = 0
def update_sizes(subplot):
global i
xs = np.linspace(0.1 * i, (10 * np.pi) + (0.1 * i), 1_000)
sizes = np.abs(np.sin(xs)) * 5
subplot["sine"].sizes = sizes
i += 1
figure[0, 0].add_animations(update_sizes)
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.run()
Total running time of the script: (0 minutes 10.880 seconds)