Note
Go to the end to download the full example code
Line Drawing PerformanceΒΆ
Display a line depicting a noisy signal consisting of a lot of points.
![line performance](../../_images/sphx_glr_line_performance_001.webp)
import numpy as np
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx
canvas = WgpuCanvas()
renderer = gfx.WgpuRenderer(canvas)
scene = gfx.Scene()
x = np.linspace(0, 100, 10_000, dtype=np.float32)
y = np.sin(x) * 30 + np.random.normal(0, 5, len(x)).astype(np.float32)
positions = np.column_stack([x, y, np.zeros_like(x)])
line = gfx.Line(
gfx.Geometry(positions=positions),
gfx.LineMaterial(thickness=2.0, color=(0.0, 0.7, 0.3, 1.0)),
)
scene.add(line)
camera = gfx.OrthographicCamera(110, 110)
camera.local.position = (50, 0, 0)
if __name__ == "__main__":
canvas.request_draw(lambda: renderer.render(scene, camera))
run()
Total running time of the script: (0 minutes 0.773 seconds)