Example: NumPy Stream¶
Streams random matrices from the server to the browser and visualises them as heatmaps. Showcases binary frame transport and incremental plotting.
Location¶
- Repository:
https://github.com/cetic/pyplet_examples - Path:
apps/pyplet_examples/examples/numpy_* - Client entry point:
numpy_client.py - Server loop:
numpy_server.py
Initialise or refresh the examples submodule:
Highlights¶
numpy_client.py:12deserialises NumPy arrays from WebSocket frames.
numpy_client.py:14seeds a liveimshowplot that updates in place.
if im is None:
im = fig.gca().imshow(array, vmin=-4, vmax=4)
plt.show()
document.getElementById("container").appendChild(document.body.lastChild)
numpy_client.py:18animates by mutating the existing image buffer.
numpy_server.py:15generates random matrices every second.
numpy_server.py:18streams the serialized bytes back to the connected client.
Great when you need a template for transporting binary data or streaming scientific visualisations.